Thursday, August 7, 2008

How to Load DataGridView in LINQ to SQL

First Step. Make sure you have sql server 2000/05/08
Second Step. If you have Database at your sql server, Add DataClasses1 in your project.
Third Step. Drag the table from your Database to your DataClasses Window.
Fourth Step. Add DataGridView to your Form and Button.

Copy this code to your button.



private void button1_Click(object sender, EventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();

var q =
from a in dc.GetTable()
select a;

Grid1.DataSource = q;
}

No comments: