DataView view = (DataView)dataSource.Select(new DataSourceSelectArguments());
DataTable groupsTable = view.ToTable();
String value;
foreach (DataRow dr in dt.Rows)
{
// Do something here IE grab the value of the first column
value = dr[0];
}
or
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
int reorderedProducts = (int)dv.Table.Rows[0][0];
if (reorderedProducts > 0)
{
Label1.Text = "Number of products on reorder: " + reorderedProducts;
}
else
{
Label1.Text = "No products on reorder.";
}
or
var view = (DataView)bindingSource1.DataSource;
DataTable productsTable = view.Table;
// Set RowStateFilter to display the current rows.
view.RowStateFilter = DataViewRowState.CurrentRows;
// Query the DataView for red colored products ordered by list price.
var productQuery = from DataRowView rowView in view
where rowView.Row.Field<string>("Color") == "Red"
orderby rowView.Row.Field<decimal>("ListPrice")
select new
{
Name = rowView.Row.Field<string>("Name"),
Color = rowView.Row.Field<string>("Color"),
Price = rowView.Row.Field<decimal>("ListPrice")
};
// Bind the query results to another DataGridView.
dataGridView2.DataSource = productQuery.ToList();
or
DataView custView = new DataView(custDS.Tables["Customers"], "",
"CompanyName, ContactName",
DataViewRowState.CurrentRows);
DataRowView[] foundRows =
custView.FindRows(new object[] {"The Cracker Box", "Liu Wong"});
if (foundRows.Length == 0)
Console.WriteLine("No match found.");
else
foreach (DataRowView myDRV in foundRows)
Console.WriteLine("{0}, {1}", myDRV["CompanyName"].ToString(),
myDRV["ContactName"].ToString());
ref:- https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/querying-the-datarowview-collection-in-a-dataview
https://stackoverflow.com/questions/5516464/sqldatasource-select-how-do-i-use-this-asp-net
https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.sqldatasource.select?view=netframework-4.8.1
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/dataset-datatable-dataview/finding-rows
No comments:
Post a Comment