1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#region Using directives using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OleDb; using System.Drawing; using System.Windows.Forms; #endregion namespace UsingADOManagedProvider { partial class ADONetForm1 : Form { public ADONetForm1( ) { InitializeComponent( ); // connect to Northwind Access database string connectionString = "provider=Microsoft.JET.OLEDB.4.0; " + "data source = c:\nwind.mdb"; // get records from the customers table string commandString = "Select CompanyName, ContactName from Customers"; // create the data set command object // and the DataSet OleDbDataAdapter DataAdapter = new OleDbDataAdapter( commandString, connectionString ); DataSet DataSet = new DataSet( ); // fill the data set object DataAdapter.Fill( DataSet, "Customers" ); // Get the one table from the DataSet 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"] + ")" ); } } } } |