我想使用搜索框过滤datagridview,我有一个适用于字符串的函数,但我不知道为什么当我使用包含int / date值的列的函数时出现异常:
public void SearchTable(TextBox searchBox, String columnNameToSearch, int Type)
{
BindingSource bs;
switch (Type)
{
case NUMERIC_COLUMN:
bs = new BindingSource
{
DataSource = _dgv.DataSource,
Filter = columnNameToSearch + " = " + searchBox.Text.Trim()
};
_dgv.DataSource = bs;
break;
case TEXT_COLUMN:
bs = new BindingSource
{
DataSource = _dgv.DataSource,
Filter = columnNameToSearch + " LIKE '" + searchBox.Text.Trim() + "%'"
};
_dgv.DataSource = bs;
break;
}
}
这是例外: http://i.stack.imgur.com/IU1Xr.png
当我在SQL服务器中尝试查询时,查询工作