怎样才能象从真正数据库中提取记录的方法,而从DataSet中提取记录呢?

fengyun14 2004-11-14 09:50:36
人们都说,dataSet就是一个内存中的数据库,那么我怎样才能象从真正数据库中提取记录的方法,而从DataSet中提取记录呢?
我用:
OleDbDataAdapter da=new OleDbDataAdapter("select 姓名,出生日期 from mytable",cn);
da.Fill(ds,"all");
填充了一个dataSet,为了加快速度,我打算从这个dataSet中查找数据,那么,我怎样才能从这个ds.Table["all"]中找到符合我条件的记录呢?如:我怎样才能找到姓名="张三"的记录呢?
同时,我怎样才能让这个结果绑定于我WinForm上的textBox1.text呢?
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
北京的雾霾天 2004-11-14
  • 打赏
  • 举报
回复
用Select方法来做:

private void GetRowsByFilter(){
DataTable myTable;
myTable = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string strExpr;
string strSort;
strExpr = "Date > '1/1/00'";
// Sort descending by column named CompanyName.
strSort = "CompanyName DESC";
DataRow[] foundRows;
// Use the Select method to find all rows matching the filter.
foundRows = myTable.Select(strExpr, strSort);
// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++){
Console.WriteLine(foundRows[i][0]);
}
}

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧