Hi,
Use data-context for this
The DataContext
is the source of all entities mapped over a database connection. It
tracks changes that you made to all retrieved entities and maintains an
"identity cache" that guarantees that entities retrieved more than one
time are represented by using the same object instance.
In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations.
public void FillGrid()
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var q =
from a in dc.GetTable<Order>()
where a.CustomerID.StartsWith("A")
select a;
dataGridView1.DataSource = q;
}
Hope this will help you