Working with Data—Defining the Table Structure
| CSharp-Online.NET:Articles |
| Database Articles |
|
© 2006 Jeffery Suddeth |
Defining the Table Structure
The following code segment defines the Customer table structure. The CustID field is defined as an auto counter field and used as the primary key.
DataTable custTable = new DataTable(); custTable.TableName = "Customers"; // this will be the primary key DataColumn custId = new DataColumn("CustID", typeof(int)); custId.AutoIncrement = true; custId.AutoIncrementSeed = 101; custId.AutoIncrementStep = 1; custTable.Columns.Add(custId); // make this the primary key custTable.PrimaryKey = new DataColumn[] { custId }; // add some fields for customer data custTable.Columns.Add(new DataColumn("Name", typeof(string))); custTable.Columns.Add(new DataColumn("Phone", typeof(string))); custTable.Columns.Add(new DataColumn("Email", typeof(string)));
|

