我正在使用存储过程填充表格。该表格允许姓名的中间名为空,但是我收到了以下错误信息:
存储过程或函数'uspInsertPersonalAccountApplication'期望提供参数'@MiddleInitial',但未提供。
谢谢!
public void ProcessForm(string[] InputData)
{
string ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["AssociatedBankConnectionString"].ToString();
SqlConnection conn = new SqlConnection(ConnString);
SqlCommand cmd = new SqlCommand("uspInsertPersonalAccountApplication", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@AccountType", "Savings");
cmd.Parameters.AddWithValue("@AccountSubType", "Savings");
cmd.Parameters.AddWithValue("@ExistingCustomer","No");
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
SqlCommandBuilder.DeriveParameters(command);
并在循环中为每个参数设置DBNull.Value
。然后再分配您想要的参数。 - Marcin或添加一个类似于
AddParamWithValueOrNull()`的扩展方法。 - Rory