1

I'm pretty familiar with SQL syntax (via MySQL) and am just getting my feet wet with C# and SQL server.

I currently have a .sdf database on my C:\ drive and want to connect to it in C#.

I added the database as a data source and now need help figuring out how to get data from the database in my C# application.

I just want to be able to set an object to the data in my SQL database so I can manipulate it using C#.

Thanks in advance for replies.

1
  • After adding the data source, I have the option to create this object: object asdf; asdf = new DBNAMEDataSet.TABLENAMEDataTable(); How can I pull data from this object? Commented May 7, 2010 at 16:05

3 Answers 3

2

A *.sdf file means you're using Compact Edition. That's a little different - more analogous to an Sqlite or Access style database than MySql or a full Sql Server.

As to the rest of it, there are as nearly many ways to do that as there are programmers. However, most of them at some level will involve the System.Data.SqlCe namespace, which is where the Sql Server Compact Edition data provider lives. If you decide to move up to a full Sql Server edition, like Sql Server Express (still free), you would instead use the System.Data.SqlClient namespace.

Additionally, I want to focus on your specific statement:

I just want to be able to set an object to the data in my SQL database so I can manipulate it using C#.

That sounds like you're really just interested in an ORM (Object/Relational Mapper). I can't comment on how well specific ORMs work with Sql Server Compact Edition, but now that you know what you're looking for you should be able to conduct your own search.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually there is ONE way to do it - hich is using the SqlCe namespace. USING the database is another thing (O/R mappers etc. come in handy), but at the end the COnnection is done in exactly one way - directly, or indirectly ;)
1

There's many ways to do this, but first off, do mean ".mdf" instead of ".sdf"?

2 Comments

The database is showing up as an .sdf. I'm not sure what the difference is. Anyway, I would like to know what the accepted standard way to do this is. Thanks!
He probably does mean sdf, for sql server compact edition. He should be careful comparing that to mysql, though - compact edition isn't in the same category as full sql server or mysql.
1

An .sdf file is a database from SQL Server Compact Edition (CE).

Try this: http://www.lfsforum.net/showthread.php?t=52392

-Krip

1 Comment

Ugh - that link teaches some bad habits (no using directive or proper connection disposal and it has a giant sql injection vulnerability)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.