我想從表中選擇列匹配給定的參數。如果參數爲空,我想從表中選擇所有記錄。下面的相關代碼是拋出這個錯誤的東西。函數的指定參數值無效。 [參數#= 1,函數的名稱(如果知道)= isnull]
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錯誤?
有用的討論: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/83821937-3929-4901-a78e-b675cf8a70ca/how-to-send-a-null-value-as -a參數 –