i want to fill dataadapter with more then one table what will be the syntax for it and binding more then one datamembers(tables) with grid
dataadapter cant be filled with table........please get the clear concept of ADO.NET by reading a good book or article.....
dataadapter is used to fill
dataset which can have more than one table.
whenever you want to bind a grid with a dataset you have to specify the tablename of that particular dataset which will be a single table.
you can have a sql query where you can merge data from more than one table and fill a dataset with those records and further bind grid with that dataset.
but if you want to show record from two different tables separately then you need two different datasets.here you can
merge two datasets and can show record of two different tables.but
keep in mind that if you want to merge two dataset then two tables of two different datasets should have the same schema
Follow the code..........
-
-
Sub BindGrid()
-
Dim myConnection as New SqlConnection (strConn)
-
-
Dim DS1 As DataSet
-
Dim DS1 As DataSet
-
Dim MyCommand As SqlDataAdapter
-
-
MyCommand = new SqlDataAdapter("exec s_get_table1", MyConnection)
-
DS1 = new DataSet()
-
MyCommand.Fill(DS1, "MyTable")
-
-
MyCommand = new SqlDataAdapter("exec s_get_table2", MyConnection)
-
DS2 = new DataSet()
-
MyCommand.Fill(DS2, "MyTable")
-
-
'The table name for both datasets are the same.
-
'Also the data type and column name for both tables are the same.
-
-
ds1.merge(ds2)
-
-
MyDataGrid.DataSource=DS1.tables(0).DefaultView
-
MyDataGrid.DataBind()
-
End Sub
-