Code to create a DataSet

Use this code to create a table and place it in a DataSet.

// Create a new DataTable.
System.Data.DataTable table = new DataTable(“Details”);
// Declare variables for DataColumn and DataRow objects.
DataColumn column;
DataRow row;
// Create new DataColumn, set DataType,
// ColumnName and add to DataTable.
column = new DataColumn();
column.DataType = System.
Type.GetType(“System.Int32”);
column.ColumnName =
“fk_agent_id”;
column.ReadOnly =
false;
column.Unique =
true;
// Add the Column to the DataColumnCollection.
table.Columns.Add(column);

// Create second column.
column = new DataColumn();
column.DataType = System.
Type.GetType(“System.String”);
column.ColumnName =
“agent_name”;
column.AutoIncrement =
false;
column.Caption =
“agent_name”;
column.ReadOnly =
false;
column.Unique =
false;
// Add the column to the table.
table.Columns.Add(column);

// Make the ID column the primary key column.
DataColumn[] PrimaryKeyColumns = new DataColumn[1];
PrimaryKeyColumns[0] = table.Columns[
“fk_agent_id”];
table.PrimaryKey = PrimaryKeyColumns;
// Instantiate the DataSet variable.
dataSet = new DataSet();
// Add the new DataTable to the DataSet.
dataSet.Tables.Add(table);