开发者

Load a DataGridView using Linq to SQL

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.

Load a DataGridView using Linq to SQL

ASP.Net :

Yes it will work. Please check this CodeProject article for step by step How to.

Load a DataGridView using Linq to SQL


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜