Searching a Dataset in VB.Net
-
Hi, I am using VB.NET 2003/MS Access. I am getting data from a table into a particular datatable in a dataset. say the data fields are ID, Name, Period and Address. I want to obtain a record from the table for a particular period and ID. How can this be done using a select statement? With Best Regards, Mayur
-
Hi, I am using VB.NET 2003/MS Access. I am getting data from a table into a particular datatable in a dataset. say the data fields are ID, Name, Period and Address. I want to obtain a record from the table for a particular period and ID. How can this be done using a select statement? With Best Regards, Mayur
SELECT * FROM TableName WHERE [ID]=@ID AND Period=@Period !alien!
-
SELECT * FROM TableName WHERE [ID]=@ID AND Period=@Period !alien!
Thnx for your reply. Can you please provide some additional steps as to how I can get the values obtained by the select statement into different variables. I am a fresher in .Net. how do you write the select statement for selecting records from datatable. your select statement - SELECT * FROM tablename WHERE [ID]=@ID AND Period=@Period how do we replace tablename with dataset.tables(0)? With Best Regards, Mayur -- modified at 0:46 Wednesday 15th February, 2006
-
Thnx for your reply. Can you please provide some additional steps as to how I can get the values obtained by the select statement into different variables. I am a fresher in .Net. how do you write the select statement for selecting records from datatable. your select statement - SELECT * FROM tablename WHERE [ID]=@ID AND Period=@Period how do we replace tablename with dataset.tables(0)? With Best Regards, Mayur -- modified at 0:46 Wednesday 15th February, 2006
This is example. Private Sub FillDataGrid() Dim strId As String = "" 'Set Id Dim strPeriod As String = "" 'Set Period Dim tableName As String = "" 'Set tableName Dim connstring As String = "" 'Set ConnectionString Dim selectSQL As String = "SELECT * FROM " + tableName + " WHERE [ID]='" + strId + "' AND Period='" + strPeriod + "'" Dim conn As New OleDb.OleDbConnection(connstring) Dim cmd As New OleDb.OleDbCommand(selectSQL, conn) Dim ds As New DataSet Dim da As New OleDb.OleDbDataAdapter(cmd) Try conn.Open() da.Fill(ds) DataGrid1.DataSource = ds.Tables(0) Catch ex As Exception MessageBox.Show(ex.Message, ex.Source) Finally If conn.State = ConnectionState.Open Then conn.Close() end if conn.Dispose() cmd.Dispose() End Try End Sub !alien!
-
This is example. Private Sub FillDataGrid() Dim strId As String = "" 'Set Id Dim strPeriod As String = "" 'Set Period Dim tableName As String = "" 'Set tableName Dim connstring As String = "" 'Set ConnectionString Dim selectSQL As String = "SELECT * FROM " + tableName + " WHERE [ID]='" + strId + "' AND Period='" + strPeriod + "'" Dim conn As New OleDb.OleDbConnection(connstring) Dim cmd As New OleDb.OleDbCommand(selectSQL, conn) Dim ds As New DataSet Dim da As New OleDb.OleDbDataAdapter(cmd) Try conn.Open() da.Fill(ds) DataGrid1.DataSource = ds.Tables(0) Catch ex As Exception MessageBox.Show(ex.Message, ex.Source) Finally If conn.State = ConnectionState.Open Then conn.Close() end if conn.Dispose() cmd.Dispose() End Try End Sub !alien!
I believe Mayur was asking about how to select data from Data Table not from Database Table. I was about to ask the same question. My case is like this.
myDataTable = PopulateDataTableFromAnyTable() for each row in myDataTable Update DatabaseTable where FieldA = row.item(0) and FieldB = row.item(1) end for
If I directly update "DatabaseTable" for each iteration, it will be really slow. So I was thinking to populate "DatabaseTable" to a Data Table, do the update in Data Table and then send the changes back to Database. The problem is how to search data in data table with one or more criteria. Thank you WiL -
I believe Mayur was asking about how to select data from Data Table not from Database Table. I was about to ask the same question. My case is like this.
myDataTable = PopulateDataTableFromAnyTable() for each row in myDataTable Update DatabaseTable where FieldA = row.item(0) and FieldB = row.item(1) end for
If I directly update "DatabaseTable" for each iteration, it will be really slow. So I was thinking to populate "DatabaseTable" to a Data Table, do the update in Data Table and then send the changes back to Database. The problem is how to search data in data table with one or more criteria. Thank you WiLHey guys, I have found the solution, I guess. Please refer to the link below. http://www.c-sharpcorner.com/Code/2004/March/DataSetsIn.NETP2.asp[^] Ofcourse, i have the same query as shiroamachi. how do you insert or update data into a datatable and finally update the database with the datatable. if anyone has any idea regarding this, plz let us know. With Best Regards, Mayur -- modified at 4:07 Wednesday 15th February, 2006