0

我编写了一个搜索查询来从 MS Access 表中查找数据。但是当用户没有像 ID 这样输入数字时,查询会失败。

"Select UID, FirstName from tUserInfo where UID = " + UserID + " and  FirstName like '%" + txtSearchFirst.Text + "%'"

数字为空时如何搜索表格?

4

2 回答 2

2
Select UID, FirstName from tUserInfo 
where (UID = " + UserID + " or UID is null)
and FirstName like '%" + txtSearchFirst.Text + "%'
于 2012-07-05T09:35:25.810 回答
0

一些笔记。

    thisCommand.CommandText = "SELECT UID, FirstName FROM tUserInfo " +
    " WHERE FirstName Like '%' & ?  & '%' And UID & "" Like ? & '%';";

    //Names are irrelevant with OLEDB and MS Access, the order is important
    thisCommand.Parameters.AddWithValue("@Param", txtSearchFirst.Text);
    thisCommand.Parameters.AddWithValue("@Param", UserID + "");
于 2012-07-05T10:33:54.003 回答