C#ASP.Net Parameters.AddWithValue拒绝参数空值 [英] C# ASP.Net Parameters.AddWithValue rejecting null value for parameter
问题描述
我使用一个存储过程填充表。该表允许一个'空'为名字的中间名首字母,但我发现了以下错误消息:
过程或函数'uspInsertPersonalAccountApplication'需要参数'@MiddleInitial,这是没有提供。
在此先感谢!
公共无效ProcessForm(字符串[] InputData)
{
串CONNSTRING = System.Configuration.ConfigurationManager.ConnectionStrings[\"AssociatedBankConnectionString\"].ToString(); 康涅狄格州的SqlConnection =新的SqlConnection(CONNSTRING);
CMD的SqlCommand =新的SqlCommand(uspInsertPersonalAccountApplication,康恩);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(@ ACCOUNTTYPE,储蓄);
cmd.Parameters.AddWithValue(@ AccountSubType,储蓄);
cmd.Parameters.AddWithValue(@ ExistingCustomer,否);
conn.Open();
cmd.ExecuteNonQuery(); conn.Close();
}
有两个选项:
修改你的存储过程,使的 @MiddleInitial 的参数可选的(这是目前不可选的,这就是为什么引发错误)
@MiddleInitial为nvarchar(10)= NULL
或者添加下面一行到code:
cmd.Parameters.AddWithValue(@ MiddleInitial,NULL);
I am populating tables using a stored procedure. The table allows a 'null' for the middle initial of the name, but I'm getting the following error message:
Procedure or function 'uspInsertPersonalAccountApplication' expects parameter '@MiddleInitial', which was not supplied.
Thanks in advance!
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();
}
There are two options here:
Modify you stored procedure and make @MiddleInitial param optional (which is currently not optional that's why error is thrown)
@MiddleInitial nvarchar(10) = NULL
Or add following line to your code:
cmd.Parameters.AddWithValue("@MiddleInitial", null);
这篇关于C#ASP.Net Parameters.AddWithValue拒绝参数空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!