C#中DataView中的Rowfilter语法 [英] Syntax of Rowfilter in DataView In C#

查看:360
本文介绍了C#中DataView中的Rowfilter语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Hi,

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
             dv = ds.Tables["Employee"].DefaultView;
             dv.RowFilter = "Deptno=" + comboBox1.SelectedItem;
             dataGridView1.DataSource = dv;
        }



谁能告诉我上面代码中的错误是什么.
我收到错误消息找不到列[System.Data.DataRowView]."

谢谢,
Thiru



Can Anybody tell me what is the error in the above code.
I am getting error "Cannot find column [System.Data.DataRowView]."

Thanks,
Thiru

推荐答案

该消息不言自明.它找不到列名.确保您的选择查询具有列名.
The message is self explanatory. It cannot find the column name. Make sure your select query has the column name.


报价:

dv.RowFilter ="Deptno = "+ comboBox1.SelectedItem;

dv.RowFilter = "Deptno=" + comboBox1.SelectedItem;


我怀疑comboBox1已绑定到数据表;那么SelectedItem的类型将为System.Data.DataRowView.

将comboBox1.SelectedItem隐式转换为字符串将产生"Deptno = System.Data.DataRowView".

试试:


I suspect that comboBox1 is bound to a datatable; then the SelectedItem will be type System.Data.DataRowView.

The implict conversion of comboBox1.SelectedItem to a string will yield "Deptno=System.Data.DataRowView".

Try:

dv.RowFilter = "Deptno=" + ((DataRowView)ComboBox1.SelectedItem).Row("Your Desired Column").ToString()


只写

dv.RowFilter ="Deptno =" + comboBox1.SelectedItem.toString();
write just

dv.RowFilter = "Deptno=" + comboBox1.SelectedItem.toString();


这篇关于C#中DataView中的Rowfilter语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆