C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to Compare two DB's and Insert/Update into Target


Posted Date: 04 Jul 2008      Total Responses: 0

Posted By: Bannai Sudheendra       Member Level: Bronze     Points: 1



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);
}






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Post Reply
You must Sign In to post a response.
Next : store procedure
Previous : how to get foreignkeys of a table
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use