我正在使用ASP.NET 4.0和SQL Server 2008 R2.I想要使用存儲過程爲「用戶註冊」網頁插入數據。每當我插入數據,錯誤顯示爲「過程或函數'usp_User_Info2'期望參數'@UserName',這是沒有提供」。但我輸入除SNo(標識列)和Vendor_ID(計算列)以外的所有必填字段。這個解決方案?而且我希望插入後在消息框中顯示「Vendor_ID」。過程或函數'usp_User_Info2'需要參數'@UserName',它沒有提供
CREATE TABLE User_Info2
(
SNo int Identity (2000,1) ,
Vendor_ID AS 'VEN' + CAST(SNo as varchar(16)) PERSISTED PRIMARY KEY,
UserName VARCHAR(16) NOT NULL,
User_Password VARCHAR(12) NOT NULL,
User_ConPassword VARCHAR(12) NOT NULL,
User_FirstName VARCHAR(25) NOT NULL,
User_LastName VARCHAR(25) SPARSE NULL,
User_Title VARCHAR(35) NOT NULL,
User_EMail VARCHAR(35) NOT NULL,
User_PhoneNo VARCHAR(14) NOT NULL,
User_MobileNo VARCHAR(14)NOT NULL,
User_FaxNo VARCHAR(14)NOT NULL,
UserReg_Date DATE DEFAULT GETDATE()
)
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_User_Info2]
@UserName VARCHAR(30),
@User_Password VARCHAR(12),
@User_ConPassword VARCHAR(12),
@User_FirstName VARCHAR(25),
@User_LastName VARCHAR(25),
@User_Title VARCHAR(35),
@User_OtherEMail VARCHAR(30),
@User_PhoneNo VARCHAR(14),
@User_MobileNo VARCHAR(14),
@User_FaxNo VARCHAR(14)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO User_Info2 (UserName,User_Password,User_ConPassword,User_FirstName,User_LastName,
User_Title,User_OtherEmail,User_PhoneNo,User_MobileNo,User_FaxNo)
VALUES (@UserName,@User_Password,@User_ConPassword,@User_FirstName,@User_LastName,
@User_Title,@User_OtherEMail,@User_PhoneNo,@User_MobileNo,@User_FaxNo)
END
protected void BtnUserNext_Click(object sender, EventArgs e)
{
SqlConnection SqlCon = new SqlConnection(GetConnectionString());
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_User_Info2";
cmd.Parameters.Add("@User_Email", SqlDbType.VarChar).Value = txtUserName.Text.Trim();
cmd.Parameters.Add("@User_Password",SqlDbType.VarChar).Value = txtRegPassword.Text;
cmd.Parameters.Add("@User_ConPassword",SqlDbType.VarChar).Value = txtRegConPassword.Text;
cmd.Parameters.Add("@User_FirstName",SqlDbType.VarChar).Value = txtRegFName.Text.Trim();
cmd.Parameters.Add("@User_LastName",SqlDbType.VarChar).Value = txtRegLName.Text.Trim();
cmd.Parameters.Add("@User_Title",SqlDbType.VarChar).Value = txtRegTitle.Text.Trim();
cmd.Parameters.Add("@User_OtherEmail", SqlDbType.VarChar).Value = txtOtherEmail.Text;
cmd.Parameters.Add("@User_PhoneNo",SqlDbType.VarChar).Value = txtRegTelephone.Text;
cmd.Parameters.Add("@User_MobileNo", SqlDbType.VarChar).Value = txtRegMobile.Text.Trim();
cmd.Parameters.Add("@User_FaxNo", SqlDbType.VarChar).Value = txtRegFax.Text.Trim();
cmd.Connection = SqlCon;
try
{
SqlCon.Open();
cmd.ExecuteScalar();
}
finally
{ string url = "../CompanyBasicInfo.aspx?Parameter=" + Server.UrlEncode
("+ Vendor_ID +");
ClientScript.RegisterStartupScript(this.GetType(), "callfunction",
"alert('Login created successfully for "+ Vendor_ID +"');
window.location.href = '" + url + "';", true);
SqlCon.Close();
}
}
你爲什麼要存儲確認的密碼?要麼匹配,要麼不匹配。並閱讀密碼散列。 – podiluska 2012-08-15 09:02:00