首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

困扰了N久的有关问题

2012-02-02 
困扰了N久的问题请教一个困扰了N久的问题:我在查询时用Filter属性筛选出姓名张三的学生,然后显示在DataGr

困扰了N久的问题
请教一个困扰了N久的问题:

我在查询时用Filter属性筛选出姓名=张三的学生,然后显示在DataGrid中

string   filter   =   "姓名= '张三 ' ";
this.StudentBindingSource.Filter=filter;
this.StudentTableAdapter.Fill(this.dBDataSet.Student);
this.StudentDataGrid.DataSource=this.StudentBindingSource;

然后,我要取出DataGrid的CurrentRowIndex的StudentName的值:
string   studentName= " ";
studentName=
          this.dBDataSet.Tables[ "Student "].Rows[StudentDataGrid.CurrentRowIndex][ "StudentName "].ToString();

问题是:
DataGrid显示的是只有张三这条记录,但我Show出来的都是其它的记录。

我个人感觉是this.dBDataSet.Tables[ "Student "].Rows这里有问题。
有人知道怎么办?谢谢了。

[解决办法]


DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "id = 1 ";
string studentName = " ";
studentName =this.ds.Tables[0].Rows[this.dataGridView1.CurrentRow.Index][ "Name "].ToString();
[解决办法]
Filer不会过滤掉datatable.rows里面的内容,而邦定的时候其实是显示的是这个datatable的defaultview的内容。
明白?

热点排行