In This Post I Am going to Explain DataTable has a Select method. This method receives a string expression that specifies what rows you want to handle. Select makes DataTables act more like small databases.
Previous Post I was explained about How to find master page control on content page in asp.net ,
How can i create a simple xml file and store it in my system in asp.net.
Gets an array of DataRow objects.
This member is overloaded. For complete information about this member, including syntax, usage, and examples
Select Method without Expression
private void GetRows()
{
// Get the DataTable of a DataSet.
DataTable table = DataSet1.Tables["Suppliers"];
DataRow[] rows = table.Select();
// Print the value one column of each DataRow.
for(int i = 0; i < rows.Length ; i++)
{
Console.WriteLine(rows[i]["CompanyName"]);
}
}
Select Method with Expression
Public void GetData()
{
// Create table.
// ... Add two columns and three rows.
DataTable table = new DataTable("Widgets");
table.Columns.Add(new DataColumn("ID", typeof(int)));
table.Columns.Add(new DataColumn("Date", typeof(DateTime)));
table.Rows.Add(100, new DateTime(2001, 1, 1));
table.Rows.Add(200, new DateTime(2002, 1, 1));
table.Rows.Add(300, new DateTime(2003, 1, 1));
// Select by date.
DataRow[] result = table.Select("Date > #6/1/2001#");
// Display.
foreach (DataRow row in result)
{
Console.WriteLine(row["ID"]);
}
}
Comments
Post a Comment