G
Guest
Does anyone know exactly how the MERGE method on the dataset functions? The
reason that I am asking is that it does not appear to be doing what I expect,
and what the documentation claims will happen (if I am understanding it
correctly).
According to the following link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskmergingdatasets.asp
You can specify merge options to achieve a variety of goals:
Add new records to one dataset by copying them from another dataset.
Update the state of records in one dataset based on another. In this
situation, the second dataset contains information not only about new
records, but also changed records and deleted records, and you want your
first dataset to reflect all these changes.
Copy not only new records and changes, but specify what to do if the
datasets do not have the same schemas.
My problem is that it will not update changed records. It will only add new
records. I have included my code below. If anyone has a suggestion, I would
greatly appreciate it.
'Get SQL Table for each table in XML File
TableName = xmlDataSet.Tables(TableLoop).TableName
SQLText = "SELECT * FROM " & TableName
Dim SQLAdapter As SqlDataAdapter = New SqlDataAdapter
SQLAdapter.SelectCommand = New SqlCommand(SQLText, SQLConnect)
Dim SQLCmdBuild As SqlCommandBuilder = New SqlCommandBuilder(SQLAdapter)
sqlDataSet = New DataSet(TableName)
'Fill Dataset with SQL Table, and then merge in XML Table
SQLAdapter.ContinueUpdateOnError = True
SQLAdapter.Fill(sqlDataSet)
sqlDataSet.Merge(xmlDataSet)
SQLAdapter.Update(sqlDataSet, TableName)
reason that I am asking is that it does not appear to be doing what I expect,
and what the documentation claims will happen (if I am understanding it
correctly).
According to the following link
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskmergingdatasets.asp
You can specify merge options to achieve a variety of goals:
Add new records to one dataset by copying them from another dataset.
Update the state of records in one dataset based on another. In this
situation, the second dataset contains information not only about new
records, but also changed records and deleted records, and you want your
first dataset to reflect all these changes.
Copy not only new records and changes, but specify what to do if the
datasets do not have the same schemas.
My problem is that it will not update changed records. It will only add new
records. I have included my code below. If anyone has a suggestion, I would
greatly appreciate it.
'Get SQL Table for each table in XML File
TableName = xmlDataSet.Tables(TableLoop).TableName
SQLText = "SELECT * FROM " & TableName
Dim SQLAdapter As SqlDataAdapter = New SqlDataAdapter
SQLAdapter.SelectCommand = New SqlCommand(SQLText, SQLConnect)
Dim SQLCmdBuild As SqlCommandBuilder = New SqlCommandBuilder(SQLAdapter)
sqlDataSet = New DataSet(TableName)
'Fill Dataset with SQL Table, and then merge in XML Table
SQLAdapter.ContinueUpdateOnError = True
SQLAdapter.Fill(sqlDataSet)
sqlDataSet.Merge(xmlDataSet)
SQLAdapter.Update(sqlDataSet, TableName)