-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: muthuseeni
Message 1 in Discussion

I need a help on this. I am trying to merge 2 datasets with same schema but 
with different values. suppose the tables are emp empid empname 1        
empname1 2        empname2    emp1 [second table]  empid empname 1        
newempname 3        empname3  primary key is empid   after merging and 
displaying in datagrid i get these values  empid empname 1        newempname 2  
      empname2 3        empname3   This is correct,of course.But when I update 
the dataset the changes are not reflected in databse.I know that when datasets 
are merged,if source and target datasets have same primay key values,the target 
datasets value is updated and RowState is set to UnChanged [if 
preservevalues=false]..but if i use preservevalues=true the source dataset is 
not updated with target datasets values.. where is the problem? how should i 
get around? please help me..   i am presenting my coding here..   SqlConnection 
conn = new SqlConnection(
    "server=(local);uid=sa;pwd=;database=Rel");
   da = new SqlDataAdapter("select * from emp", conn);
   
   SqlDataAdapter da1 = new SqlDataAdapter("select * from emp1", conn);
       da.TableMappings.Add("Table", "emp");
   da1.TableMappings.Add("Table", "emp");    ds = new DataSet("emp");
   DataSet ds1 = new DataSet("emp");    da.MissingSchemaAction = 
    MissingSchemaAction.AddWithKey;
  
   da.Fill(ds);
   da1.MissingSchemaAction = MissingSchemaAction.AddWithKey;
   
   da1.Fill(ds1);
   
   ds.Merge(ds1.Tables[0] ,false,MissingSchemaAction.AddWithKey);
   
   da.UpdateCommand=new SqlCommand("update emp set [EMAIL PROTECTED] where 
[EMAIL PROTECTED]",conn);
   da.UpdateCommand.Parameters.Add ("@empname",SqlDbType.Char ,10,"empname");
   da.UpdateCommand.Parameters.Add ("@empid",SqlDbType.Int,4,"empid");
   
   if (ds.HasChanges()==true)
   {
    MessageBox.Show ("changes");
   }
   dataGrid1.DataSource=ds;
   da.Update(ds);   Thanks in advance.

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to