Hi I am trying to compare two database(Source and Target).I am able compare,get the changes but I am not able to update my target with my changes.I am trying to do this with data set and data adapter. I am using the DataAdapter's update method to update my target database.
DataSet ds1, ds2; SqlConnection cn1, cn2; SqlDataAdapter da1, da2; private void AssignConnectionString() { try { cn2 = new SqlConnection(TestMaterialPluginMassMerge.Properties.Settings.Default.remoteConnectionSettings.ToString()); cn1 = new SqlConnection(TestMaterialPluginMassMerge.Properties.Settings.Default.localConnectionString.ToString()); } catch (Exception Ex) { System.Diagnostics.Debug.WriteLine(Ex.Message); } } private void button1_Click(object sender, EventArgs e) { this.AssignConnectionString(); this.GetLocalData(); this.GetRemoteData(); this.MergeData(); try { if (cn1.State != ConnectionState.Open) { cn1.Open(); } da1.Update(ds1, "A"); da1.Update(ds1, "B"); da1.Update(ds1, "C"); da1.Update(ds1, "D"); da1.Update(ds1, "E"); da1.Update(ds1, "F"); } catch (Exception Ex) { System.Diagnostics.Debug.WriteLine(Ex.Message); } } private void GetLocalData() { try { ds1 = new DataSet(); cn1.Open(); da1 = new SqlDataAdapter("select * from A", cn1); da1.Fill(ds1, "Material"); da1 = new SqlDataAdapter("select * from B", cn1); da1.Fill(ds1, "materialModelType"); da1 = new SqlDataAdapter("select * from C", cn1); da1.Fill(ds1, "ModelParameter"); da1 = new SqlDataAdapter("select * from D", cn1); da1.Fill(ds1, "ModelParameterDefinition"); da1 = new SqlDataAdapter("select * from E", cn1); da1.Fill(ds1, "TableParameter"); da1 = new SqlDataAdapter("select * from F", cn1); da1.Fill(ds1, "EMAWeight"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { da1.Dispose(); cn1.Close(); } } private void GetRemoteData() { try { ds2 = new DataSet(); cn2.Open(); da2 = new SqlDataAdapter("select * from A", cn2); da2.Fill(ds2, "Material"); da2 = new SqlDataAdapter("select * from B", cn2); da2.Fill(ds2, "materialModelType"); da2 = new SqlDataAdapter("select * from C", cn2); da2.Fill(ds2, "ModelParameter"); da2 = new SqlDataAdapter("select * from D", cn2); da2.Fill(ds2, "ModelParameterDefinition"); da2 = new SqlDataAdapter("select * from E", cn2); da2.Fill(ds2, "TableParameter"); da2 = new SqlDataAdapter("select * from F", cn2); da2.Fill(ds2, "EMAWeight"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { da2.Dispose(); cn1.Close(); } } private void MergeData() { ds1.Merge(ds2, true); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|