1
Answer

update a database, using merge and getChanges

matthias.lietz

matthias.lietz

20y
2.7k
1
Hallo, I need some help. I want/ need to write a little program to update an database. Structure update and data update. I want to use VB.NET (and Ado.NET). There are two databases - a source and a target. At the end, they should have the same structure and content. I want to try it first with one table, which exists and has the same name in both databases. (Connection, provider - this works... - so I don’t have it in the code example... ) I have two datasets, fill it, and think the best way is to use the "merge-method" and then I proof "HasChanges". If there are Changes on the Database, I want to use the "getChanges"-method. But this doesn’t work. What ever I try, after the " If myDS1.HasChanges()" question the program always jumps to "endif". I tried different variant’s (for instance: "myDS1.Merge(myDS2, False, MissingSchemaAction.Add)"), but always the same result. Think I have a problem in my logic. If somebody could give me an advice/ help or tell me where my mistake is ... . thanks Here is one version of what I tried: Imports System.Data Imports System.Data.OleDb Module Module1 Sub Main() Dim myDS1 As New DataSet() Dim myTable1 As New DataTable("TPPerson") ‘ here I’m not sure myDS1.Tables.Add(myTable1) Dim strSQL1 = "Select * from TPPerson" adp1 = New OleDbDataAdapter(strSQL1, cnn1) adp1.Fill(myDS1, "TPPerson") Dim myDS2 As New DataSet() Dim myTable2 As New DataTable("TPPerson") myDS2.Tables.Add(myTable2) Dim strSQL2 = "Select * from TPPerson" adp2 = New OleDbDataAdapter(strSQL2, cnn2) adp2.Fill(myDS2, "TPPerson") myDS1.Merge(myTable2, False, MissingSchemaAction.Add) ‘ here could be a mistake myDS1.AcceptChanges() If myDS1.HasChanges() _ Then Dim myDS3 As New DataSet() myDS3 = myDS1.GetChanges(DataRowState.Modified) myDS1.Merge(myDS3, False, System.Data.MissingSchemaAction.Add) adp1.Update(myDS1, "TPPerson") End If
Answers (1)
0
sacresp
NA 458 0 20y
Just comment out the generated types in reference.cs And remember to add using YourNamespaceThatContainsTheLibrary
0
mr_bart_simpson
NA 16 0 21y
Well, in my opinion, the problem is that it generates the Type anyway. No matter, if it already has a direct reference to it or not. I tried it with just giving the Webservice no name while importing into VS.net, but what happend did not work: I got two (crashing) types with the same name, because the auto-generated one resists in the same namespace. When I gave a name to the webservice the new type get's its own namespace and that results in a different type for the framework. Maybe this is an bug in the importing tool, that generates the source, but I don't know, wether someone intenionally thought about that and the way I try to use it. Bart Simpson
0
spgilmore
NA 591 0 21y
That's a toughie. Sorry. I'm a little curious why it produces a type that is different than the original. I wonder if you're using a primitive type in your complex type that doesn't convert directly to an XML primitive type. Food for thought...
0
mr_bart_simpson
NA 16 0 21y
Wether or not this is a good feature, is a point you could argue about... Normaly it is very good, but in my special case it isn't. I'm using a class library both on client- and on serverside. But importing the webservice always generates new types, no matter wether the original type are already accesible or not. And so I alway have to map between types used in my library and the types that are automatically generated... Because I'm still developing the library, there are sometimes changes in the transmitted classes, and I' alway have to rewrite the conversion methods, too. The best way out that I found was using reflection to automatically do this job. But this only works with primitive types like int or string or something... Anny suggestions how to do better? Thx in advance Bart Simpson
0
spgilmore
NA 591 0 21y
That's one of the good things about Web Services. WSDL allows web service clients to figure out the types used in the server without knowing anything else about it. Your WSDL import tool reads the type definition from the WSDL document and generates the necessary types for you. Use the autogenerated type.
Next Recommended Forum