【发布时间】:2014-02-13 12:12:45
【问题描述】:
我正在尝试将数据插入到 MS SQL 数据库表中,当其他字段为空时出现此错误
其他列的 Allow Nulls 设置为 true
Additional information: Procedure or function 'spCustomerRegistration' expects parameter '@other', which was not supplied.
型号代码
SqlCommand cmd = new SqlCommand("spCustomerRegistration", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@firstname", txtFirstName);
cmd.Parameters.AddWithValue("@lastname", txtLastName);
cmd.Parameters.AddWithValue("@stateid", ddLocation1);
cmd.Parameters.AddWithValue("@urbanrural", txtStatUR);
cmd.Parameters.AddWithValue("@cityid", city_id);
cmd.Parameters.AddWithValue("@areaid", area_id);
cmd.Parameters.AddWithValue("@streetid", street_id);
cmd.Parameters.AddWithValue("@townid", town_id);
cmd.Parameters.AddWithValue("@villageid", village_id);
cmd.Parameters.AddWithValue("@houseno", txtHouseNo);
cmd.Parameters.AddWithValue("@dob", Convert.ToDateTime(DOB));
cmd.Parameters.AddWithValue("@customeremail", txtEmail);
cmd.Parameters.AddWithValue("@customerphone", _phone_number);
cmd.Parameters.AddWithValue("@gender", ddGender);
cmd.Parameters.AddWithValue("@password", dal.Encryptdata(txtPassword));
cmd.Parameters.AddWithValue("@customeripaddress", _cip);
cmd.Parameters.AddWithValue("@regcode", _regcode);
cmd.Parameters.AddWithValue("@customerguid", _CustomerGuid);
cmd.Parameters.AddWithValue("@other", txtOthers);
cmd.Parameters.Add("@retval", SqlDbType.Int);
cmd.Parameters["@retval"].Direction = ParameterDirection.Output;
cmd.Parameters.Add("@userid", SqlDbType.Int, 0, "id");
cmd.Parameters["@userid"].Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteNonQuery();
retval = (int)cmd.Parameters["@retval"].Value;
pk_uid = (int)cmd.Parameters["@userid"].Value;
con.Close();
存储过程
BEGIN
SET NOCOUNT ON;
IF NOT EXISTS(SELECT * FROM CustomerRegistration WHERE CustomerEmail =@customeremail or CustomerPhone=@customerphone )
BEGIN
INSERT INTO CustomerRegistration (FirstName ,LastName ,StateID, Urban_Rural, CityID, AreaID, StreetID, TownID, VillageID, HouseNo, DOB, CustomerEmail, CustomerPhone, Gender, Password, CustomerIPAddress, RegCode, CustomerGuid, Other ) VALUES (@firstname, @lastname, @stateid, @urbanrural, @cityid, @areaid, @streetid, @townid, @villageid, @houseno, @dob, @customeremail, @customerphone, @gender, @password, @customeripaddress, @regcode, @customerguid, @other )
SELECT @userid = SCOPE_IDENTITY();
SET @retval=1
END
ELSE
BEGIN
SET @retval =0
SET @userid =0
END
【问题讨论】:
标签: sql sql-server asp.net-mvc razor