hai friends

I am one dataset like this ds like three columns this:

tblkey Empkey Empname

T101 E10 Natraj
T102 E11 Siva
T103 E14 ganesh

I am having another dataset ds1 only two columns like this:

Empkey Empname
E10 karthi
E11 thriu
E13 maran

i waant merge the dataset and check the values while checking if ds is not having E13 it should bind and show the result like this ds

tblkey Empkey Empname

T101 E10 Natraj
T102 E11 Siva
T103 E14 ganesh
E13 maran
here 'tblkey' comes empty
how to do:

1 Answer

To replicate your example entirely:

DataSet ds1 = new DataSet(); DataSet ds2 = new DataSet(); ds1.Tables.Add(new DataTable()); ds2.Tables.Add(new DataTable()); ds1.Tables[0].Columns.Add("tblkey"); ds1.Tables[0].Columns.Add("empkey"); ds1.Tables[0].Columns.Add("empname"); ds2.Tables[0].Columns.Add("empkey"); ds2.Tables[0].Columns.Add("empname"); ds1.Tables[0].Rows.Add("T101", "E10", "Natraj"); ds1.Tables[0].Rows.Add("T102", "E11", "Siva"); ds1.Tables[0].Rows.Add("T103", "E14", "ganesh"); ds2.Tables[0].Rows.Add("E10", "karthi"); ds2.Tables[0].Rows.Add("E11", "thriu"); ds2.Tables[0].Rows.Add("E13", "maran"); // primary keys must be set in order for the merge to work ds1.Tables[0].PrimaryKey = new DataColumn[] { ds1.Tables[0].Columns["empkey"] }; ds2.Tables[0].PrimaryKey = new DataColumn[] { ds2.Tables[0].Columns["empkey"] }; // this is the critical line ds1.Merge(ds2, true, MissingSchemaAction.Add); 

Adding the missing schema (in this case, the tblkey column) is achieved by setting the third parameter correctly.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.