Reputation: 2380
How can I use Linq-To-SQL to load a DataGridView?
Would the following work?
DCDataContext db = new DCDataContext();
dataGridViewJobs.DataSource = db.jobs.Select(p => p.closeDate <= DateTime.Now);
Upvotes: 0
Views: 7553
Reputation: 3219
Winforms :
Alternately You can use BindingSource and DataGridView. You can give your Linq to SQL entity as DataSource to BindingSOurce. BindingSource will work as Datasource to DataGridView.
bindingSource1.DataSource = items;
dataGridView1.DataSource = bindingSource1;
You can find how To here.
ASP.Net :
Yes it will work. Please check this CodeProject article for step by step How to.
Upvotes: 2
Reputation: 12396
Yes. But you should change your query, since select is not used for querying like in sql but for projecting the elements of a sequence into a new form.
The following example should work:
DCDataContext db = new DCDataContext();
dataGridViewJobs.DataSource = (from jobs in db.jobs
where p.closeDate <= DateTime.Now
select jobs);
Upvotes: 1