| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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? |
|
#5
| |||
| |||
| 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? |
|
#6
| |||
| |||
| 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? |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.