Programmatically creating a DataSet object : DataSet « ADO.net Database « ASP.Net

Home
ASP.Net
1.ADO.net Database
2.Ajax
3.Asp Control
4.Collections
5.Components
6.Data Binding
7.Development
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
13.Network
14.Page
15.Request
16.Response
17.Server
18.Session Cookie
19.Sitemap
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
24.WebPart
25.WPF
26.XML
ASP.Net » ADO.net Database » DataSet 
Programmatically creating a DataSet object

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
  void Page_Load(object sender, EventArgs e)
  {
      DataSet customerOrders = new DataSet("CustomerOrders");
      DataTable customers = customerOrders.Tables.Add("Customers");
      DataTable orders = customerOrders.Tables.Add("Orders");
      
      customers.Columns.Add("CustomerID", Type.GetType("System.Int32"));
      customers.Columns.Add("FirstName", Type.GetType("System.String"));
      customers.Columns.Add("LastName", Type.GetType("System.String"));
      customers.Columns.Add("Phone", Type.GetType("System.String"));
      customers.Columns.Add("Email", Type.GetType("System.String"));
      orders.Columns.Add("CustomerID", Type.GetType("System.Int32"));
      orders.Columns.Add("OrderID", Type.GetType("System.Int32"));
      orders.Columns.Add("OrderAmount", Type.GetType("System.Double"));
      orders.Columns.Add("OrderDate", Type.GetType("System.DateTime"));
      customerOrders.Relations.Add("Cust_Order_Rel", customerOrders.Tables["Customers"].Columns["CustomerID"], customerOrders.Tables["Orders"].Columns["CustomerID"]);    
      DataRow row = customers.NewRow();
      row["CustomerID"1;
      row["FirstName""first";
      row["LastName""last";
      row["Phone""111-1111";
      row["Email""[email protected]";
      customers.Rows.Add(row);    
      row = orders.NewRow();
      row["CustomerID"1;
      row["OrderID"22;
      row["OrderAmount"0;
      row["OrderDate""11/10/2007";
      orders.Rows.Add(row);
      Response.Write(Server.HtmlEncode(customerOrders.GetXml()));     
      gridResults.DataSource = customerOrders.Tables["Customers"];
      gridResults.DataBind();
  }
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
  <title>Programmatically creating a DataSet object</title>
</head>
<body>
  <form id="form1" runat="server">
    <div>     
        <asp:GridView runat="Server" ID="gridResults" />   
    </div>
  </form>
</body>
</html>

 
Related examples in the same category
1.Loop through data in Sql Server by DataSet
2.Loop through DataSet
3.Get query result from DataSet
4.Load Table from DataSet
5.Build a DataSet
6.Create DataSet pragmatically
7.Build a DataSet with relationship
8.Output the content of a DataSet as XML
9.Finding a Particular Row in a DataSet
10.Converting XML to DataSet and Vice versa
11.Converting XML to DataSet and Vice versa (VB)
12.DataSet Serialization and Deserialization using Binary Format
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.