only My site

Saturday, December 13, 2008

Merge DataSet


DataSet.Merge(ds)
==============

For the merge to take place between the datasets, apart from the data type and column name, the table name should also be the same.
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")

'Now the code works because 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()

No comments: