比较用于筛选数据表 c# 的文本框



我想将两个文本框与数据表中的数据进行比较,并使用此比较操作来过滤日期表。例如:我想显示值为 x 的所有数据(行和列(,其中:

textbox1.text>x>textbox1.text

我在字符串格式中使用了" Like"运算符来获取与文本框中的值完全匹配的值,但我无法执行所需的范围过滤操作

这是我与指定问题相关的代码:

 dv.RowFilter = string.Format("Type Like '%{0}%' and Gain Like" +
            "'%{1}%'" +
            "and Year Like'%{2}%' and MotorPower Like '%{3}%'" +
            "and Profit Like '%{4}%'", textBoxType .Text,textBoxGain.Text
            , textBoxYear.Text, textBoxBiggerthan.Text, textBoxKar.Text);
 dataGridView1.DataSource = dv;

我有另一个名为 textBoxSmallerthan.Text 的输入文本框我想在数据表(数据网格视图(中将我的电机功率列的范围设置为textBoxBiggerthan.TexttextBoxSmallerthan.Text

此处的文档显示数字不需要用单引号制造商包装。所以格式是:

Columnname < Number

所以最终的过滤器应该是这样的:

dv.RowFilter = string.Format("Type Like '%{0}%' and Gain Like" +
            "'%{1}%'" +
            "and Year Like'%{2}%' and MotorPower > {3} and MotorPower < {4}" +
            "and Profit Like '%{4}%'", textBoxType .Text,textBoxGain.Text
            , textBoxYear.Text, textBoxSmallerthan.Text, textBoxBiggerthan.Text, textBoxKar.Text);
 dataGridView1.DataSource = dv;

最新更新