How can I use Linq-To-SQL to load a DataGri开发者_运维百科dView?
Would the following work?
DCDataContext db = new DCDataContext();
dataGridViewJobs.DataSource = db.jobs.Select(p => p.closeDate <= DateTime.Now);
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.
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);
精彩评论