Monday, February 20, 2012

Problem with Dataset.Merge

Hello guyz,
I am using SQL server and I want to merge two datasets. I have two tables which are similar in structure-(same number of columns). I want to display these two tables in one datagrid. I have 5 rows in the first table and 3 on the other. So in the datagrid it should have 8 rows. Part of my code is below…

ConnectToDatabaseServer()
Dim querystr As String = ("Select username, password from PublicAccounts")
Dim da As SqlDataAdapter = new SqlDataAdapter(querystr, myConnection)
Dim ds1 As DataSet = new DataSet()
da.Fill(ds1, "firsttable")

querystr = ("Select username, password from EmployeeAccounts")
Dim da2 As SqlDataAdapter = new SqlDataAdapter(querystr, myConnection)
Dim ds2 As DataSet = new DataSet()
da2.Fill(ds2, "secondtable")

ds1.Merge(ds2,False, System.Data.MissingSchemaAction.Add)
MergeGrid.DataSource = ds1
MergeGrid.DataBind()
myConnection.Close()

This code only displays the contents of ds1 (5 rows).
My table structure are as follows:
PublicAccounts (username Char(50), password char(50), pid integer primary key)
EmployeeAccounts (username Char(50), password char(50), eid integer primary key)

I really would appreciate any help.
Thank you..couple of ideas. nothing jumps out at me immediately. try setting preservechanges to true (the second parameter of the ds1.Merge) just for grins.

also, try wrapping the merge in a try-catch block and see if any errors are being thrown. that might help narrow it down.

cs

No comments:

Post a Comment