views:

53

answers:

1

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?

+1  A: 

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());
}
RedFilter
@red thank you. how can i bind one of the the controls to the dataset?
i am a girl
@red MyDbDataContext the compiler is not recognizing this word
i am a girl
Error 1 The type or namespace name 'DbDataContext' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\agordon\Local Settings\Application Data\Temporary Projects\WpfApplication1\Window1.xaml.cs 29 33 WpfApplication1
i am a girl
Umm, `MyDB` is example text, as is all other code starting with "My". You'll need to replace `MyDB` with whatever you named your model, etc.
RedFilter
@red what is the default? DataClasses1?
i am a girl