Tutorial on displaying datasets from a SQL Server database using C#
I am using Visual Studio 2008 and I am a beginner.
I am connecting to a SQL Server 2008 database.
I would like to display data from a tab开发者_Python百科le.
How do I do this? Can someone please show me an easy tutorial?
An easy way to get started is with LINQ To SQL.
Use this tutorial to set up LINQ To SQL for your database. You only need to follow the Create LINQ to SQL Classes section.
Then, you access the data like this:
using (var db = new MyDbDataContext())
{
var myRecord= db.MyTable.FirstOrDefault();
Console.WriteLine(myRecord.MyColumn.ToString());
}
精彩评论