class Test
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
DataTable dt;
DataRow[] drs;
DataRow dr;
//Create a datatable
dt = new DataTable();
dt.Columns.Add("Id",Type.GetType("System.Int16"));
dt.Columns.Add("Name",System.Type.GetType("System.String"));
//Add two rows to the data table
dr = dt.NewRow();
dr["ID"]=10;
dr["Name"]="John";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["ID"]=11;
dr["Name"]="Bobski";
dt.Rows.Add(dr);
//Filter using the datatable select which returns an array of datarows
//load the array of data roes with all rows with an ID = 10
drs = dt.Select("id = 11");
Console.WriteLine("Using datatable select");
Console.WriteLine("ID={0} and Name={1}",drs[0]["ID"].ToString(),drs[0]["Name"] );
//Line below causes error because select only returns one row
//Console.WriteLine("ID={0} and Name={1}",drs[1]["ID"].ToString(),drs[1]["Name"] );
//Filter Using the
dt.DefaultView.RowFilter = "id=11";
Console.WriteLine("Using a view on the datatable");
Console.WriteLine("ID={0} and Name={1}",dt.DefaultView[0]["ID"].ToString(),dt.DefaultView[0]["Name"] );
//Line Below causes error as the dataview only contains one row
//Console.WriteLine("ID={0} and Name={1}",dt.DefaultView[1]["ID"].ToString(),dt.DefaultView[1]["Name"] );
String Ret;
Ret=Console.ReadLine();
}
}