【问题标题】:Filtering results from textbox to DataGridView从文本框过滤结果到 DataGridView
【发布时间】:2014-07-01 18:30:39
【问题描述】:

我想从现有的 DataGridView 表中过滤/搜索一些结果。除了一个领域,我已经完成了大部分。这是我的 DataGridView 表“产品 ID”的第一个字段,它是一个 Int 数据类型字段。所以我认为它需要将 Int 值转换为 System.String .. 但我不知道如何解决这个问题.. 任何人都可以帮助我..

private void txtSearch_TextChanged(object sender, EventArgs e)
    {
        try 
        {
            DataView DV = new DataView(dbdataset);
            DV.RowFilter = string.Format("Convert[Product ID,'System.String'] LIKE '%{0}%' OR [Product Name] LIKE '%{0}%' OR [Brand Name] LIKE '%{0}%' OR [Pro. Size ID] LIKE '%{0}%'", Convert.ToString(txtSearch.Text));
            dgView.DataSource = DV;
        }
         catch (Exception ex)
        {
            Error_txt.Text = ex.Message;
        }

    }

报错

Syntax error: Missing operand after '[Product ID,'System.String()']' operator.

【问题讨论】:

    标签: c# search datagridview filtering


    【解决方案1】:

    我终于弄明白了。现在我可以过滤整数和字符串输入。

    DV.RowFilter = string.Format("Convert([Product ID], System.String) LIKE '%{0}%' OR [Product Name] LIKE '%{0}%' OR [Brand Name] LIKE '%{0}%' OR [Pro. Size ID] LIKE '%{0}%'", txtSearch.Text);
    

    【讨论】:

      猜你喜欢
      • 2013-01-31
      • 2012-07-25
      • 2012-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多