akbar ansari

akbar ansari

  • 1.7k
  • 64
  • 2.1k

merged more than 3 tables in asp.net c#

Oct 6 2019 5:56 AM
string Data_1 = "SELECT Col_1, Col_2, Col_3 from Table1 WHERE and Col_1='condition'";
Data_2 += "SELECT Col_4, Col_5, Col_6 from Table2 WHERE and Col_4='condition'";
Data_3 += "SELECT Col_7, Col_8, Col_9 from Table3 WHERE and Col_7='condition'";
 
SqlCommand comandName= new SqlCommand(Data_1, connection);
SqlDataAdapter adpr = new SqlDataAdapter(comandName);
DataSet ds = new DataSet();
adpr.Fill(ds);
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
DataTable dt3 = new DataTable();
dt1 = ds_1.Tables[0];
dt2 = ds_1.Tables[1];
dt3 = ds_1.Tables[2];
if (dt1.Rows.Count > 0 || dt2.Rows.Count > 0 || dt3.Rows.Count)
{
dt1.Merge(dt2);
dt1.Merge(dt3);
Repeater1.DataSource = dt1;
Repeater1.DataBind();
}
 
Respected Developer's 
we required a solution please help
 
Result its done , but result shows like this
 
 Col_1   Col_4 Col_7
 1  
 2 2 
 3 1 1
 4  4
 
 
 
But I want result of this types
 
 
Col_1 Col_4 Col_7
12 1
2   1 4
3

4 
 
please help...
 

Answers (2)