Hi Steve,
You can create a dataset and its tables from code, below you will find an
example of how to create two tables and a FK relationship.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
products = new DataSet("StaticTables");
#region The Category table
DataTable table = new DataTable("Category");
DataColumn pkCol = table.Columns.Add("CategoryID", typeof(int));
pkCol.AutoIncrementSeed=0;
pkCol.AutoIncrement = true;
table.Columns.Add("Name", typeof(string));
table.Columns.Add("ParentID", typeof(int));
table.Columns.Add("OriginalName", typeof(string));
table.PrimaryKey = new DataColumn[] {pkCol};
products.Tables.Add( table);
//Insert the default category
DataRow row = table.NewRow();
row["Name"]="";
row["ParentID"]=0;
row["OriginalName"]="";
table.Rows.Add( row);
#endregion
#region The Product Table
table = new DataTable("Product");
pkCol = table.Columns.Add("ProductID", typeof(int));
pkCol.AutoIncrement = true;
pkCol.AutoIncrementSeed = 1;
table.Columns.Add("Name", typeof(string));
table.Columns.Add("UPC", typeof(string));
table.Columns.Add("PriceLevel0", typeof(double));
table.Columns.Add("CategoryID", typeof(int));
table.Columns.Add("OnHand", typeof(double));
table.Columns.Add("Active", typeof(bool));
table.PrimaryKey = new DataColumn[] {pkCol};
products.Tables.Add( table);
#endregion
#region The Product Category Relationship
DataRelation fkRel = new DataRelation( "ProductCategory",
products.Tables["Category"].Columns["CategoryID"],
products.Tables["Product"].Columns["CategoryID"]);
products.Relations.Add( fkRel);
#endregion
Steve Wasser said:
Can someone tell me if it is possible to manually create a DataSet (without
a Sqlconnection), then create a table via code and add that table to the
dataset? I'm trying to take a master table and split it into many different
tables based on a particular column value. Or, is there an easier
parent/child system I should use?
Thanks again!