ComponentOne ADO.NET DataExtender
ADO.NET DataExtender Task-Based Help / Using C1DataViewSet with an Untyped ADO.NET DataSet / Fetching Data from the Server at Run Time
In This Topic
    Fetching Data from the Server at Run Time
    In This Topic

    To fetch data from the server at run time by the click of a button, complete the following steps:

    1. Double-click button1 (in the sample project, the Create Orders and Fill button at the right of dataGridView2) to bring up the Button1_Click event handler and replace it with the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
         ordersDataAdapter.Fill(dataSet1)
         Dim tb As DataTable = dataSet1.Tables("Orders")
         tb.PrimaryKey = New DataColumn() {tb.Columns("OrderID")}
         ordersDataGrid.DataSource = dataSet1
         ordersDataGrid.DataMember = "Orders"
         Button1.Enabled = False
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void button1_Click(object sender, EventArgs e)
      {
         ordersDataAdapter.Fill(dataSet1);
         DataTable tb = dataSet1.Tables["Orders"];
         tb.PrimaryKey = new DataColumn[] { tb.Columns["OrderID"] };
         ordersDataGrid.DataSource = dataSet1;
         ordersDataGrid.DataMember = "Orders";
         button1.Enabled = false;
      }
      
    2. Double-click button2 (in the sample project, the Create OrderDetails and Fill button at the top right of dataGridView3) to bring up the Button2_Click event handler and enter the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
         ordDetDataAdapter.Fill(dataSet1)
         Dim tb As DataTable = dataSet1.Tables("Order Details")
         tb.PrimaryKey = New DataColumn() {tb.Columns("OrderID"), tb.Columns("ProductID")}
         ordDetDataGrid.DataSource = dataSet1.Tables("Order Details")
         Button2.Enabled = False
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void button2_Click(object sender, EventArgs e)
      {
          ordDetDataAdapter.Fill(dataSet1);
          DataTable tb = dataSet1.Tables["Order Details"];
          tb.PrimaryKey = new DataColumn[] { tb.Columns["OrderID"], tb.Columns["ProductID"] };
          ordDetDataGrid.DataSource = dataSet1.Tables["Order Details"];
          button2.Enabled = false;
      }
      End Sub
      
    3. Double-click button3 (in the sample project, the Create Relation button at the bottom right of dataGrid3) to bring up the Button3_Click event handler and enter the following code:

      To write code in Visual Basic

      Visual Basic
      Copy Code
      Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
         Dim rel As New DataRelation("Orders - Order Details", dataSet1.Tables("Orders").Columns("OrderID"), dataSet1.Tables("Order Details").Columns("OrderID"))
         dataSet1.Relations.Add(rel)
         Button3.Enabled = False
      End Sub
      

      To write code in C#

      C#
      Copy Code
      private void button3_Click(object sender, EventArgs e)
      {
          DataRelation rel = new DataRelation("Orders - Order Details",
          dataSet1.Tables["Orders"].Columns["OrderID"],
          dataSet1.Tables["Order Details"].Columns["OrderID"]);
          dataSet1.Relations.Add(rel);
          button3.Enabled = false;
      }
      

    Run the application and observe the following: