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 开发者_JAVA技巧manipulate it using C#.
Thanks in advance for replies.
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.
There's many ways to do this, but first off, do mean ".mdf" instead of ".sdf"?
An .sdf file is a database from SQL Server Compact Edition (CE).
Try this: http://www.lfsforum.net/showthread.php?t=52392
-Krip
精彩评论