我正在尝试为下面的代码中的第一个参数传递一个空值,但MySQL抱怨
Incorrect number of arguments for PROCEDURE myProc; expected 2, got 1
当我手动调用第一个参数为null的过程时,它可以工作,但是当EmptyAsNullStartsWith(employeeNumberText.Text)
返回null时,它会抱怨。
Database db = DatabaseFactory.CreateDatabase(
ConfigurationManager.AppSettings["dbType"]
);
DbCommand cmd = db.GetStoredProcCommand("staff_listforinquiry");
db.AddeParameter(
cmd,
"in_employeeNumber",
DbType.String,
EmptyAsNullStartsWith(employeeNumberText.Text)
);
db.AddeParameter(
cmd,
"in_name",
DbType.String,
EmptyAsNullContains(employeeNameText.Text)
);
答案 0 :(得分:2)
您是否尝试过EmptyAsNullContains(employeeNameText.Text)返回DBNull而不是常规null?
答案 1 :(得分:0)
if(employeeNumberText.Text != "")
db.AddInParameter(dbCommand, "in_employeeNumber", DbType.String, employeeNumberText.Text);
else
db.AddInParameter(dbCommand, "in_employeeNumber", DbType.String, DBNull.Value);