Reputation: 87
I have created a database with Microsoft SQL Server Management Studio (Microsoft SQL Server 2008). I've been searching around but either I don't understand it or can't find it, but how do I connect from within my project (Visual Studio 2010 Enterprise) so that I can send and receive data from the DB? My database name is MyDB.
var database = new MyDB();
In Solution Explorer, right-click References, and then click Add Reference.
In the Add Reference dialog box, click .NET, click the System.Data.Linq assembly, and then click OK.
The assembly is added to the project.
Add the following directives at the top of Program.cs:
Upvotes: 4
Views: 10296
Reputation: 166
The easiest way to add the ability to have an app communicate with a SQL Server database is to use LINQ to SQL. Assuming you've already made a database connection in the Server Explorer pane, then:
Caveat: While this is the arguably the simplest way to get quick connectivity to a database, there are others that will have better performance and/or features like nHibernate or Microsoft's Entity Framework as Coding Gorilla also suggested.
Upvotes: 5
Reputation: 19842
LINQ is not an OR/M, and so it does not "connect to a database" per-se. LINQ is Language INtegrated Query, and simply provides language constructs for querying data sources (not all of which are necessarily databases).
Maybe you are interested in LINQ-To-SQL, in which case you should do some reading on that subject as it's not quite in the realm of an SO question and answer to give you a full tutorial on how to use it.
You may also decide to look at other OR/M's which may make use of LINQ, such as the Entity Framework, or NHibernate.
Upvotes: 2