Cannot perform 'Like' operation on System.Int32 and System.String. DataGridView search and filter

后端 未结 3 1247
旧时难觅i
旧时难觅i 2020-12-16 03:49

I have a form that when I select a column name from a ComboBox, and type in a text box it filters and displays the searched criteria in the DataGridView. When I search for \

相关标签:
3条回答
  • 2020-12-16 04:00

    Try this perhaps?

    dv.RowFilter = "'%" + comboSearch.Text.Trim() + "%' like '%" + searchTxt.Text.Trim() + "%'";
    

    It may just be a missing quotation, because the query reads as

    "   123 like '%123%'   "
    
    0 讨论(0)
  • 2020-12-16 04:13

    the code tried to search from gridview (devexpress)..

       DataRow[] dr = dt.Select("invoiceId ='" + Convert.ToInt32(gridView1.GetRowCellValue(id, "invoiceId")) + "' AND  '%" + Convert.ToDouble(gridView1.GetRowCellValue(id, "Amount_Paid")) + "%' LIKE   '%" + Convert.ToDouble(gridView1.GetRowCellValue(id, "Amount")) + "%' ");
    
                        if (dr.Length > 0)
                        {
                            MessageBox.Show("already paid");
                        }
    
    0 讨论(0)
  • 2020-12-16 04:17

    Convert the number to a string inside the filter:

    dv.RowFilter = string.Format("CONVERT({0}, System.String) like '%{1}%'",
                                 comboSearch.Text.Trim(), searchTxt.Text.Trim());
    
    0 讨论(0)
提交回复
热议问题