Linking a .Net 2003 DataGrid with a query
-
I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!
-
I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!
You can put the DataSet as a DataSource, then the DataMember property should be the name of a table in the DataSet.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
You can put the DataSet as a DataSource, then the DataMember property should be the name of a table in the DataSet.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.
-
That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.
You should probably look for a good book on interacting with VB and databases.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this? The reason I want to do that is because I need to do operations in the grid, but I really don't know how. That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.
ford86 wrote:
That's what I'm doing right now, but I don't want the DataMember to be a table but rather a query. Is there a way to to this?
No, there isn't. Any query is going to return the results in either a DataSet (multiple tables) or a DataTable object. If your query is returning data from a single table, you can keep it in a DataTable and bind the DataGridView to that.
ford86 wrote:
That's why I did a Query in MSAcces, but I can't use it as a dataSource for the grid.
Of course you can!! The exact same query is going to return results in a DataTable or DataSet. Seriously, you need to pickup a book on VB.NET and/or ADO.NET and work through it.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I want my dataGrid's DataSource to be a Query from my MSAccess Database, but I can only put a DataTable from a DataSet as the DataSource. Is there an other way that the DataSource can be linked with my Query? (...too many "data" in this question...) Thanks!
Hi, You can assign a join query to DataAdapter, fill the DataSet, Create a DataView and link it to the table, apply filter on the RowFilter Property of DV Private DS As New DataSet Private DA As SqlClient.SqlDataAdapter Private DV As DataView ... Dim ConnString As String = "Data Source...." DA = New SqlClient.SqlDataAdapter("SELECT ... FROM Table1 INNER JOIN Table2 ON ...", ConnString) DA.Fill(DS, "TwoTables") DV = New DataView(DS.Tables("TwoTables")) dg.DataSource = DV ... DV.RowFilter = "ID = 2" ' > < <> ... Note: Update here has some restrictions! hope this helps :)
NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...
-
Hi, You can assign a join query to DataAdapter, fill the DataSet, Create a DataView and link it to the table, apply filter on the RowFilter Property of DV Private DS As New DataSet Private DA As SqlClient.SqlDataAdapter Private DV As DataView ... Dim ConnString As String = "Data Source...." DA = New SqlClient.SqlDataAdapter("SELECT ... FROM Table1 INNER JOIN Table2 ON ...", ConnString) DA.Fill(DS, "TwoTables") DV = New DataView(DS.Tables("TwoTables")) dg.DataSource = DV ... DV.RowFilter = "ID = 2" ' > < <> ... Note: Update here has some restrictions! hope this helps :)
NajiCo http://www.InsideVB.NET[^] It's nice 2b important, but it's more important 2b nice...
Not sure if you can use
SqlDataAdapter
on Access databases. That is for SQL Server...."The clue train passed his station without stopping." - John Simmons / outlaw programmer