当我搜索文本框字段时;我在C#上收到错误
System.Data.SqlClient.SqlException:'。'附近的语法不正确。
代码:
private string SearchCondition()
{
string StartDate = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(pdtStartDate.Value.Year.ToString() + "/" + pdtStartDate.Value.Month.ToString() + "/" + pdtStartDate.Value.Day.ToString()));
string EndDate = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(pdtEndDate.Value.Year.ToString() + "/" + pdtEndDate.Value.Month.ToString() + "/" + pdtEndDate.Value.Day.ToString()));
string SearchString = " And DateRemember Between '" + StartDate + "' And '" + EndDate + "'";
if (!string.IsNullOrEmpty(txtSubject.Text.Trim()))
{
SearchString += " And Subject Like %" + txtSubject.Text.Trim() + "%";
}
return SearchString;
}
答案 0 :(得分:0)
从短暂的一瞥中,我认为你错过了'%'周围的引号。围绕txtSearch的价值,不是吗?