using System; using System.Data; using db = System.Data.OleDb; // File: DataSetFillViaCommandAndViaDataAdapter.cs(.txt) // (Re)written By: Dan Garlen February 2004 // as part of a C# ADO.NET demonstration series // Requires: ConsoleUtilityRoutines.cs & C:\TestData\Northwind.mdb namespace ADOdotNET_Demos { public class DataSetFillViaCommandAndViaDataAdapter { public static string strSQL = "SELECT * FROM [Customers]"; public static string strMDB = "C:\\TestData\\Northwind.mdb"; public static string strDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data source =" + strMDB; static void Main(string[] args) { cur.Title("DataSet Fill Via Command & DataAdapter"); Demo(); cur.Footer(); } public static void Demo() { db.OleDbConnection cn = new db.OleDbConnection(); cn.ConnectionString = strDB; try { // Setup Command db.OleDbCommand cmd; // cmd = new db.OleDbCommand(strSQL,cn); // cmd.CommandType = CommandType.Text; // or ... cmd = new db.OleDbCommand(); cmd.CommandText = strSQL; cmd.CommandType = CommandType.Text; // This is the default type cmd.Connection = cn; // Setup DataAdapter db.OleDbDataAdapter da = new db.OleDbDataAdapter(); da.SelectCommand = cmd; // Create and Fill DataSet DataSet ds = new DataSet(); da.Fill(ds, "MyTableName"); cur.ShowDataSet(ds); cn.Close(); } catch (Exception ex) {cur.WL("DB Error", ex.Message.ToString());} } } }