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 Answer 1

1

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());
}
Sign up to request clarification or add additional context in comments.

5 Comments

thank you. how can i bind one of the the controls to the dataset?
MyDbDataContext the compiler is not recognizing this word
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
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.
what is the default? DataClasses1?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.