I see!
That's a pain - there is no standard way to do that unless there is common information between the two tables. If there is, it's pretty simple JOIN stuff.
But it is possible. Add this method:
private DataTable MergeColumns(DataTable dt1, DataTable dt2)
{
DataTable result = new DataTable();
foreach (DataColumn dc in dt1.Columns)
{
result.Columns.Add(new DataColumn(dc.ColumnName, dc.DataType));
}
foreach (DataColumn dc in dt2.Columns)
{
result.Columns.Add(new DataColumn(dc.ColumnName, dc.DataType));
}
for (int i = 0; i < Math.Max(dt1.Rows.Count, dt2.Rows.Count); i++)
{
DataRow dr = result.NewRow();
if (i < dt1.Rows.Count)
{
for (int c = 0; c < dt1.Columns.Count; c++)
{
dr[c] = dt1.Rows[i][c];
}
}
if (i < dt2.Rows.Count)
{
for (int c = 0; c < dt2.Columns.Count; c++)
{
dr[dt1.Columns.Count + c] = dt2.Rows[i][c];
}
}
result.Rows.Add(dr);
}
return result;
}
Then just use it in your code:
string USN = "4PS12MCA28";
string Name = "Partha";
string FName = "Krishnappa";
string CC = "P11MCA41";
string CTIT = "JAVA";
DataTable DT2 = new DataTable();
DataTable DT1 = new DataTable();
DT1.Columns.Add("USN");
DT1.Columns.Add("Name");
DT1.Columns.Add("FName");
DT2.Columns.Add("CC");
DT2.Columns.Add("C_Title");
DataRow DR = DT1.NewRow();
DR["USN"] = USN;
DR["Name"] = Name;
DR["FName"] = FName;
DT1.Rows.Add(DR);
DataRow DR1 = DT2.NewRow();
DR1["CC"] = CC;
DR1["C_Title"] = CTIT;
DT2.Rows.Add(DR1);
dataGridView1.DataSource = MergeColumns(DT1, DT2);