Using ADO Managed Provider : OleDbDataAdapter « ADO.Net « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Windows.Forms;

   class ADONetForm1 : Form
   {
      public ADONetForm1()
      {
         InitializeComponent();
         string connectionString = "provider=Microsoft.JET.OLEDB.4.0; data source = c:\\nwind.mdb";
         string commandString = "Select CompanyName, ContactName from Customers";
         OleDbDataAdapter DataAdapter = new OleDbDataAdapter(
         commandString, connectionString );
         DataSet DataSet = new DataSet();

         DataAdapter.Fill( DataSet, "Customers" );

         DataTable dataTable = DataSet.Tables[0];

         // for each row in the table, display the info
         foreach ( DataRow dataRow in dataTable.Rows )
         {
            lbCustomers.Items.Add(
               dataRow["CompanyName"] +
               " (" + dataRow["ContactName"] + ")" );
         }
      }
      private void InitializeComponent()
      {
         this.lbCustomers = new System.Windows.Forms.ListBox();
         this.SuspendLayout();

         this.lbCustomers.FormattingEnabled = true;
         this.lbCustomers.Location = new System.Drawing.Point( 13, 13 );
         this.lbCustomers.Name = "lbCustomers";
         this.lbCustomers.Size = new System.Drawing.Size( 267, 225 );
         this.lbCustomers.TabIndex = 0;

         this.AutoScaleBaseSize = new System.Drawing.Size( 5, 13 );
         this.ClientSize = new System.Drawing.Size( 292, 262 );
         this.Controls.Add( this.lbCustomers );
         this.Name = "ADONetForm1";
         this.Text = "ADO.Net Form 1";
         this.ResumeLayout( false );

      }

      private System.Windows.Forms.ListBox lbCustomers;

      [STAThread]
      static void Main()
      {
         Application.Run( new ADONetForm1() );
      }
   }








32.10.OleDbDataAdapter
32.10.1.Updating a DataSource
32.10.2.Using MultiTabled Datasets
32.10.3.Using ADO Managed Provider