using System; using System.Data; using db = System.Data.OleDb; // File: DataSetDataViewLoop.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 DataSetDataViewLoop { 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("Northwind DataSet DataView Loop"); Demo(); cur.Footer(); } public static void Demo() { db.OleDbConnection cn = new db.OleDbConnection(); cn.ConnectionString = strDB; try { db.OleDbCommand cmd; // Setup Command cmd = new db.OleDbCommand(strSQL,cn); cmd.CommandType = CommandType.Text; db.OleDbDataAdapter da = new db.OleDbDataAdapter(); // Setup DataAdapter da.SelectCommand = cmd; DataSet ds = new DataSet(); // Create and Fill DataSet da.Fill(ds, "MyTableName"); DataView dv; dv = new DataView(ds.Tables["MyTableName"]); dv.RowFilter = "ContactName LIKE 'C%' "; // <<<<<<<<<< RowFilter dv.Sort = "ContactName"; //<<<<<<<<<<< Sort foreach (DataRowView drv in dv) // Iterate through the rows of the DataView. { for (int i = 0; i < 3; i++) Console.Write(drv[i] + "\t"); cur.WL(""); } cn.Close(); } catch (Exception ex) {cur.WL("DB Error", ex.Message.ToString());} } } }