我正在尝试在以下搜索功能中实现 ORDER BY 功能:
public DataSet SearchTable()
{
string sql1 = "SELECT * from dbo.Documents1 order by Received_Date";
bool flag = false;
if (!txtRef.Text.Equals(""))
{
if (flag == false)
{
sql1 = sql1 + " where Ref LIKE N'%" + txtRef.Text + "%'";
flag = true;
}
else
{
sql1 = sql1 + " and Ref LIKE N'%" + txtRef.Text + "%'";
}
}
if (!txtSubject.Text.Equals(""))
{
if (flag == false)
{
sql1 = sql1 + " where Subject LIKE N'%" + txtSubject.Text + "%'";
flag = true;
}
else
{
sql1 = sql1 + " and Subject LIKE N'%" + txtSubject.Text + "%'";
}
}
我收到以下错误:
Incorrect syntax near the keyword 'where'.
知道如何解决吗?提前致谢。