[英]How to Pass MySQL null parameter on DbCommand in Enterprise Library
I'm trying to pass a null value for the first parameter in the code below, but MySQL complains that 我试图在下面的代码中为第一个参数传递一个空值,但是MySQL抱怨
Incorrect number of arguments for PROCEDURE myProc; expected 2, got 1
When I manually call the procedure with the first argument as null, it works, but when EmptyAsNullStartsWith(employeeNumberText.Text)
returns null, it complains. 当我使用第一个参数为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)
);
您是否尝试过EmptyAsNullContains(employeeNameText.Text)返回DBNull而不是常规null?
if(employeeNumberText.Text != "")
db.AddInParameter(dbCommand, "in_employeeNumber", DbType.String, employeeNumberText.Text);
else
db.AddInParameter(dbCommand, "in_employeeNumber", DbType.String, DBNull.Value);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.