C# ASP.Net Parameters.AddWithValue rejecting null value for parameter

前端 未结 7 1812
臣服心动
臣服心动 2021-01-18 04:22

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:

7条回答
  •  耶瑟儿~
    2021-01-18 04:41

    add the parameter for MiddleInitial also with Null value

    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");
            cmd.Parameters.AddWithValue("@MiddleInitial",DBNull.Value);
            conn.Open();
            cmd.ExecuteNonQuery();
    
            conn.Close();
        }
    

提交回复
热议问题