C#ASP.Net Parameters.AddWithValue拒绝参数空值 [英] C# ASP.Net Parameters.AddWithValue rejecting null value for parameter

查看:313
本文介绍了C#ASP.Net Parameters.AddWithValue拒绝参数空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个存储过程填充表。该表允许一个'空'为名字的中间名首字母,但我发现了以下错误消息:

过程或函数'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆