views:

156

answers:

2

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);
+1  A: 

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);
Raúl Roa
the dataGridView dosn't have a DataBind method. This is the grid view for forms no asp.net.
roncansan
Sorry, but you have a tag for asp .net and the questions asks for a GridView not a DataGridView
Raúl Roa
@unknown (google) : Please mention this fact in your question. How will he know it is asp.net or winforms using that two lines of code.
Mahin
Apologize, I make the suggestions
roncansan
+1  A: 
Mahin