从数据集中查找特定行 [英] finding a particular row from dataset
本文介绍了从数据集中查找特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据库中有一个表.我已经使用dataadapter和数据集绑定到gridview.我想在数据集中找到特定的记录.找到该记录后,我想将其绑定到另一个gridview.
请帮我谢谢.
i have a table in database. i have binded to gridview using dataadapter and dataset. I want to find particular record in dataset. After finiding that record i want to bind it to another gridview.
please help me thank you.
推荐答案
如果使用Dataview并将行过滤为:
会更好
Hi,
It Would be Better if you use Dataview and filter the Row as :
DataView dvwData = new DataView(ds.Tables[0]);
dvwData.RowFilter = "";
dvwData.RowFilter = "PrimaryKey = '" + PrimaryKeyValue + "'";
ds是您的数据集
现在,您可以将dvwData作为数据源绑定到第二个gridView.
希望这对您有帮助...
Here ds is Your Dataset
Now you can bind your second gridView with dvwData as DataSource..
Hope This May Help You...
希望它能对您有所帮助.
Hi,
Hope it help you .
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=test;Integrated Security=True");
string statment = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt from Items ";
SqlDataAdapter da = new SqlDataAdapter(statment, con);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow[] foundRows = ds.Tables[0].Select("item_code = 1", " item_code DESC", DataViewRowState.CurrentRows);
//this is for create datatable with same schema like the orginal one .
string statment2 = "select item_code, Item_name, brand, size, section, price, Material, Qty, tax, tt from Items where item_code = 0";
SqlDataAdapter da2 = new SqlDataAdapter(statment2, con);
DataTable dt = new DataTable();
da2.Fill(dt);
DataRow dr = dt.NewRow();
foreach (DataRow row in foundRows)
{
dr[0] = row[0];
dr[1] = row[1];
dr[2] = row[2];
dr[3] = row[3];
dr[4] = row[4];
dr[5] = row[5];
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
</asp:GridView>
</div>
最好的问候
M.Mitwalli
Best Regards
M.Mitwalli
可以使用DataGrid
的SelectedItem
属性来检索当前单元格值,如此处所述.
http://msdn.microsoft .com/en-us/library/system.windows.controls.datagrid.selecteditem(v = vs.95).aspx#Y600 [ http://msdn.microsoft.com/en-us/library/b5c0xc84.aspx [ ^ ]
The current cell value can be retrieved using theSelectedItem
property ofDataGrid
as explained here.
http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selecteditem(v=vs.95).aspx#Y600[^]
thenDataRows
can be retrieved from theDataTable
ofDataSet
usingSelect
method ofDataTable
as explained here
http://msdn.microsoft.com/en-us/library/b5c0xc84.aspx[^]
这篇关于从数据集中查找特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文