我正在尝试为一家银行显示其贷方/借方应用程序,但是当我在文本框中过滤该应用程序时,找不到数据! 希望你能帮助我!
string filter = "";
string command = "SELECT * FROM Movimentos WHERE [Tipo de Movimento] IN('Crédito')";
if (textTipodeMovimento.Text != "")
{
filter = filter + "[Tipo de Movimento] LIKE '%" + textTipodeMovimento.Text + "%'AND";
}
if (filter.Length > 0)
{
Sqldata.DataSource = SqlDataSource1;
string FinalFilter = filter.Remove(filter.Length - 3);
SqlDataSource1.SelectCommand = command + FinalFilter;
Sqldata.DataBind();
}
else
{
Sqldata.DataBind();
}
}
答案 0 :(得分:-1)
如果只更正您的代码,它将像:
string command = "SELECT * FROM Movimentos WHERE [Tipo de Movimento] = 'Crédito'"; // no need to use IN statement if there is only a check for 1 value
if (textTipodeMovimento.Text != "")
{
command += String.Format(" AND lower([Tipo de Movimento]) LIKE '%{0}%'", textTipodeMovimento.Text.ToLower());
}
Sqldata.DataBind();