for example
Code:
// Create DataTable A
private DataTable CreateDataTableA()
{
DataTable aTable = new DataTable("A");
DataColumn dtCol;
DataRow dtRow;
// Create ID column and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.Int32");
dtCol.ColumnName = "ID";
dtCol.AutoIncrement = true;
dtCol.Caption = "ID";
dtCol.ReadOnly = true;
dtCol.Unique = true;
// Add the column to the DataColumnCollection.
aTable.Columns.Add(dtCol);
// Create Name column and add to the table
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.String");
dtCol.ColumnName = "FName";
dtCol.AutoIncrement = false;
dtCol.Caption = "First Name";
dtCol.ReadOnly = false;
dtCol.Unique = false;
aTable.Columns.Add(dtCol);
// Create Last Name column and add to the table.
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.String");
dtCol.ColumnName = "LName";
dtCol.AutoIncrement = false;
dtCol.Caption = "Last Name";
dtCol.ReadOnly = false;
dtCol.Unique = false;
aTable.Columns.Add(dtCol);
// Create three rows to the table
dtRow = aTable.NewRow();
dtRow["ID"] = 1001;
dtRow["FName"] = "Mahesh";
dtRow["LName"] = "Chand" ;
aTable.Rows.Add(dtRow);
dtRow = aTable.NewRow();
dtRow["ID"] = 1002;
dtRow["FName"] = "Melanie";
dtRow["LName"] = "Talmadge" ;
aTable.Rows.Add(dtRow);
dtRow = aTable.NewRow();
dtRow["ID"] = 1003;
dtRow["FName"] = "Vinay";
dtRow["LName"] = "Bansal" ;
aTable.Rows.Add(dtRow);
return aTable;
}
// Create DataTable B
private DataTable CreateDataTableB()
{
DataTable bTable = new DataTable("B");
DataColumn dtCol;
DataRow dtRow;
// Create ID column and add to the DataTable.
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.Int32");
dtCol.ColumnName = "CustomerID";
dtCol.AutoIncrement = true;
dtCol.Caption = "CustomerID";
dtCol.ReadOnly = true;
dtCol.Unique = true;
// Add the column to the DataColumnCollection.
bTable.Columns.Add(dtCol);
// Create Name column and add to the table
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.String");
dtCol.ColumnName = "Name";
dtCol.AutoIncrement = false;
dtCol.Caption = "Name";
dtCol.ReadOnly = false;
dtCol.Unique = false;
bTable.Columns.Add(dtCol);
// Create Last Name column and add to the table.
dtCol = new DataColumn();
dtCol.DataType= System.Type.GetType("System.String");
dtCol.ColumnName = "Address";
dtCol.AutoIncrement = false;
dtCol.Caption = "Address";
dtCol.ReadOnly = false;
dtCol.Unique = false;
bTable.Columns.Add(dtCol);
// Create three rows to the table
dtRow = bTable.NewRow();
dtRow["CustomerID"] = 11;
dtRow["Name"] = "Mr. Peter Ferrera";
dtRow["Address"] = "9th Street, Bank Road, NOIDA" ;
bTable.Rows.Add(dtRow);
dtRow = bTable.NewRow();
dtRow["CustomerID"] = 21;
dtRow["Name"] = "Ross Tomo";
dtRow["Address"] = "North Street, Parkway Road, SunCity" ;
bTable.Rows.Add(dtRow);
dtRow = bTable.NewRow();
dtRow["CustomerID"] = 31;
dtRow["Name"] = "Dr. Jog Rocky";
dtRow["Address"] = "Turnpike Avenue, Philly" ;
bTable.Rows.Add(dtRow);
return bTable;
}