returning a table + LINQ

This is a discussion on returning a table + LINQ within the ADO DAO RDO RDS forums in Framework and Interface Programming category; Hi, I wanted to know how we can return the whole table using linq and use that table to bind to a DataGridView in Win Forms. Below is the code sample which I am trying but get a compile error as we cannot return var. Any code sammple would really help. public var GetAllProducts() { DataContext db = new DataContext(); var products = from p in db.Products select p; return products; } -Thanks...

Go Back   Application Development Forum > Framework and Interface Programming > ADO DAO RDO RDS

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-07-2008, 12:33 PM
Sampat
Guest
 
Default returning a table + LINQ

Hi,
I wanted to know how we can return the whole table using linq and
use that table to bind to a DataGridView in Win Forms. Below is the
code sample which I am trying but get a compile error as we cannot
return var. Any code sammple would really help.


public var GetAllProducts()
{
DataContext db = new DataContext();
var products = from p in db.Products
select p;
return products;
}

-Thanks
Reply With Quote
  #2  
Old 09-07-2008, 10:48 PM
Sampat
Guest
 
Default Re: returning a table + LINQ

On Sep 7, 9:33*am, Sampat <sampatdi...@gmail.com> wrote:
> Hi,
> * *I wanted to know how we can return the whole table using linq and
> use that table to bind to a DataGridView in Win Forms. Below is the
> code sample which I am trying but get a compile error as we cannot
> return var. Any code sammple would really help.
>
> *public var GetAllProducts()
> * * * * {
> * * * * * * DataContext db = new DataContext();
> * * * * * * var products = from p in db.Products
> * * * * * * * * * * * * * *select p;
> * * * * * * return products;
> * * * * }
>
> -Thanks


Also, is there a sample which shows how to update data using
DataGridView + LINQ + Datbabase.
Reply With Quote
  #3  
Old 09-08-2008, 12:27 AM
Cor Ligthert[MVP]
Guest
 
Default Re: returning a table + LINQ

You mean something like this

private void Form1_Load(object sender, EventArgs e)
{
FillDataGridView(bindingSource1);
dataGridView1.DataSource = (bindingSource1);
}
private void FillDataGridView(BindingSource bindingSource)
{
NorthwindDataContext dc = new NorthwindDataContext();
bindingSource.DataSource = dc.Employees;
}

Cor



"Sampat" <sampatdixit@gmail.com> schreef in bericht
news:563dac8a-1c22-4bce-98e9-4d0d5cb37350@w1g2000prk.googlegroups.com...
> Hi,
> I wanted to know how we can return the whole table using linq and
> use that table to bind to a DataGridView in Win Forms. Below is the
> code sample which I am trying but get a compile error as we cannot
> return var. Any code sammple would really help.
>
>
> public var GetAllProducts()
> {
> DataContext db = new DataContext();
> var products = from p in db.Products
> select p;
> return products;
> }
>
> -Thanks


Reply With Quote
  #4  
Old 09-08-2008, 01:34 AM
Sampat
Guest
 
Default Re: returning a table + LINQ

On Sep 7, 9:27*pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
> You mean something like this
>
> private void Form1_Load(object sender, EventArgs e)
> *{
> * * * FillDataGridView(bindingSource1);
> * * * dataGridView1.DataSource = (bindingSource1);
> *}
> *private void FillDataGridView(BindingSource bindingSource)
> {
> * * * NorthwindDataContext dc = new NorthwindDataContext();
> * * * bindingSource.DataSource = dc.Employees;
>
> }
>
> Cor
>
> "Sampat" <sampatdi...@gmail.com> schreef in berichtnews:563dac8a-1c22-4bce-98e9-4d0d5cb37350@w1g2000prk.googlegroups.com...
>
> > Hi,
> > * I wanted to know how we can return the whole table using linq and
> > use that table to bind to a DataGridView in Win Forms. Below is the
> > code sample which I am trying but get a compile error as we cannot
> > return var. Any code sammple would really help.

>
> > public var GetAllProducts()
> > * * * *{
> > * * * * * *DataContext db = new DataContext();
> > * * * * * *var products = from p in db.Products
> > * * * * * * * * * * * * * select p;
> > * * * * * *return products;
> > * * * *}

>
> > -Thanks


Thanks..and how does editing gridview data from UI update the object
and then internally the database table?
Reply With Quote
  #5  
Old 09-08-2008, 02:08 PM
Cor Ligthert[MVP]
Guest
 
Default Re: returning a table + LINQ

Sampat,

That is very easy,

\\\
NorthwindDataContext dc = (NorthwindDataContext)
((System.Data.Linq.Table<Employee>)bindingSource1. DataSource).Context
;
dc.SubmitChanges();
///

Cor


"Sampat" <sampatdixit@gmail.com> schreef in bericht
news:397c3a0e-a9cc-4d2c-aa5d-8181f7e41b7d@z6g2000pre.googlegroups.com...
On Sep 7, 9:27 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
> You mean something like this
>
> private void Form1_Load(object sender, EventArgs e)
> {
> FillDataGridView(bindingSource1);
> dataGridView1.DataSource = (bindingSource1);
> }
> private void FillDataGridView(BindingSource bindingSource)
> {
> NorthwindDataContext dc = new NorthwindDataContext();
> bindingSource.DataSource = dc.Employees;
>
> }
>
> Cor
>
> "Sampat" <sampatdi...@gmail.com> schreef in
> berichtnews:563dac8a-1c22-4bce-98e9-4d0d5cb37350@w1g2000prk.googlegroups.com...
>
> > Hi,
> > I wanted to know how we can return the whole table using linq and
> > use that table to bind to a DataGridView in Win Forms. Below is the
> > code sample which I am trying but get a compile error as we cannot
> > return var. Any code sammple would really help.

>
> > public var GetAllProducts()
> > {
> > DataContext db = new DataContext();
> > var products = from p in db.Products
> > select p;
> > return products;
> > }

>
> > -Thanks


Thanks..and how does editing gridview data from UI update the object
and then internally the database table?

Reply With Quote
  #6  
Old 09-08-2008, 02:11 PM
Cor Ligthert[MVP]
Guest
 
Default Re: returning a table + LINQ

Second attempt.

Sampat,

That is very easy,

\\\
NorthwindDataContext dc = (NorthwindDataContext)
((System.Data.Linq.Table<Employee>)bindingSource1. DataSource).Context
;
dc.SubmitChanges();
///

Cor


"Sampat" <sampatdixit@gmail.com> schreef in bericht
news:397c3a0e-a9cc-4d2c-aa5d-8181f7e41b7d@z6g2000pre.googlegroups.com...
On Sep 7, 9:27 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
> You mean something like this
>
> private void Form1_Load(object sender, EventArgs e)
> {
> FillDataGridView(bindingSource1);
> dataGridView1.DataSource = (bindingSource1);
> }
> private void FillDataGridView(BindingSource bindingSource)
> {
> NorthwindDataContext dc = new NorthwindDataContext();
> bindingSource.DataSource = dc.Employees;
>
> }
>
> Cor
>
> "Sampat" <sampatdi...@gmail.com> schreef in
> berichtnews:563dac8a-1c22-4bce-98e9-4d0d5cb37350@w1g2000prk.googlegroups.com...
>
> > Hi,
> > I wanted to know how we can return the whole table using linq and
> > use that table to bind to a DataGridView in Win Forms. Below is the
> > code sample which I am trying but get a compile error as we cannot
> > return var. Any code sammple would really help.

>
> > public var GetAllProducts()
> > {
> > DataContext db = new DataContext();
> > var products = from p in db.Products
> > select p;
> > return products;
> > }

>
> > -Thanks


Thanks..and how does editing gridview data from UI update the object
and then internally the database table?

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 01:58 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.