我想从列与给定参数匹配的表中进行选择。如果参数为空,我想从表中选择所有记录。下面的相关代码是引发此错误的原因。
private static string _dbJobCreate =
"CREATE TABLE Job (jID int primary key identity(1,1), jAddress nvarchar(64) not null);";
private static string _dbJobSelect =
"SELECT jID FROM Job WHERE jAddress = @jAddress OR @jAddress IS NULL";
public static DataTable GetJobs(string jAddress)
{
SqlCeParameter pjAddress = new SqlCeParameter();
pjAddress.ParameterName = "@jAddress";
if (!string.IsNullOrEmpty(jAddress))
{
pjAddress.Value = jAddress;
}
else
{
pjAddress.Value = DBNull.Value;
}
return ExecuteDataTable(_dbJobSelect, pjAddress);
}
例外:The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = isnull ]
如何在 SQLCE 中有效地完成此操作而不会出错?