6
Reply

i want to merge two tables in dataset.

Pavan Bujji

Pavan Bujji

Oct 24 2016 9:25 AM
248
im getting the exception cannot find table 0.
 
My code is
 
con = new SqlConnection(strConString);
con.Open();
cmd = new SqlCommand("select * from Empdetails", con);
cmd.CommandType = CommandType.Text;
Da = new SqlDataAdapter(cmd);
Ds = new DataSet();
Da.Fill(Ds, "Empdetails");
cmd = new SqlCommand("select * from EmpTable", con);
cmd.CommandType = CommandType.Text;
Da = new SqlDataAdapter(cmd);
Ds = new DataSet();
Da.Fill(Ds, "EmpTable");
Grdtables.DataSource = Ds.Tables[0];
Grdtables.DataBind();
con.Close();
Ds.Tables[0].Merge(Ds.Tables[1]);
Dt = Ds.Tables[0];
for (i = 0; i <= Dt.Rows.Count - 1; i++)
{
Response.Write(Dt.Rows[i].ItemArray[0] + " -- " + Dt.Rows[i].ItemArray[1]);
}
}
 
 Please give me the solution.
 
 
 
Regards,
Pavan. 

Answers (6)