简体   繁体   中英

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

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM