tags:

views:

104

answers:

3

Hey everyone,

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  A: 

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

Kevin Raffay
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!
Soo
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.
Joel Coehoorn
+1  A: 

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

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

-Krip

Krip
Ugh - that link teaches some bad habits (no using directive or proper connection disposal and it has a giant sql injection vulnerability)
Joel Coehoorn
+2  A: 

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.

Joel Coehoorn
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 ;)
TomTom