我编写了一个搜索查询来从 MS Access 表中查找数据。但是当用户没有像 ID 这样输入数字时,查询会失败。
"Select UID, FirstName from tUserInfo where UID = " + UserID + " and FirstName like '%" + txtSearchFirst.Text + "%'"
数字为空时如何搜索表格?
Select UID, FirstName from tUserInfo
where (UID = " + UserID + " or UID is null)
and FirstName like '%" + txtSearchFirst.Text + "%'
一些笔记。
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 + "");