Created
January 20, 2016 11:08
-
-
Save bjoerntx/17f8d2e8155040023d4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Index() | |
{ | |
DataSet ds = new DataSet(); | |
// create the outer table that has a relation | |
// to the child table "product" | |
DataTable dtReport = new DataTable("report"); | |
dtReport.Columns.Add("report_id", | |
Type.GetType("System.Int32")); | |
dtReport.Rows.Add(new object[] { 0 }); | |
ds.Tables.Add(dtReport); | |
// create a table "products" | |
DataTable dtProduct = new DataTable("product"); | |
dtProduct.Columns.Add(new DataColumn("report_id", | |
Type.GetType("System.Int32"))); | |
dtProduct.Columns.Add(new DataColumn("Product_ID", | |
Type.GetType("System.Int32"))); | |
dtProduct.Columns.Add(new DataColumn("Product_Name", | |
Type.GetType("System.String"))); | |
dtProduct.Columns.Add(new DataColumn("product_Price", | |
Type.GetType("System.Int32"))); | |
dtProduct.Rows.Add(new object[] { 0, 1, "Product 1", 1000 }); | |
dtProduct.Rows.Add(new object[] { 0, 2, "Product 2", 2000 }); | |
dtProduct.Rows.Add(new object[] { 0, 3, "Product 3", 3000 }); | |
ds.Tables.Add(dtProduct); | |
// create the relation | |
ds.Relations.Add(new DataRelation("relation1", | |
dtReport.Columns["report_id"], | |
dtProduct.Columns["report_id"], false)); | |
// fill the ViewBag and return the view | |
ViewBag.dataSet = ds; | |
return View(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment