Alex Gordon
Alex Gordon

Reputation: 60691

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 table.

How do I do this? Can someone please show me an easy tutorial?

Upvotes: 1

Views: 914

Answers (1)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171371

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());
}

Upvotes: 1

Related Questions