这是我的SP:
CREATE PROCEDURE _insertAdminProfile
(
@Ad_Fname VARCHAR(25),
@Ad_Lname VARCHAR(25),
@Ad_DOB DATE,
@Ad_Sex VARCHAR(25),
@Ad_Address VARCHAR(200),
@Ad_Phone VARCHAR(12),
@Ad_Email VARCHAR(25),
@Ad_Pwd VARCHAR(7) OUTPUT
)
AS BEGIN
DECLARE @MyTableVar TABLE (Ad_Pwd VARCHAR(7));
INSERT INTO dbo.Admin_Profile (Ad_Fname, Ad_Lname, Ad_DOB, Ad_Sex,Ad_Address,Ad_Phone,Ad_Email)
OUTPUT INSERTED.Ad_Regid INTO @MyTableVar
VALUES (@Ad_Fname, @Ad_Lname, @Ad_DOB, @Ad_Sex, @Ad_Address, @Ad_Phone, @Ad_Email)
SELECT @Ad_Pwd = Ad_Pwd
FROM @MyTableVar
END
这是我的代码:
protected void cmdprofile_Click(object sender, EventArgs e)
{
string _gender;
if (rdomale.Checked)
{
_gender = "Male";
}
else
{
_gender = "Female";
}
Class1.con = CreateConnection();
cmd = new SqlCommand("_insertAdminProfile", Class1.con );
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Ad_Fname", txtfname.Text);
cmd.Parameters.AddWithValue("@Ad_Lname", txtlname.Text);
cmd.Parameters.AddWithValue("@Ad_DOB", txtdob.Text);
cmd.Parameters.AddWithValue("@Ad_Sex", _gender);
cmd.Parameters.AddWithValue("@Ad_Address", txtaddress.Text);
cmd.Parameters.AddWithValue("@Ad_Phone", txtphone.Text);
cmd.Parameters.AddWithValue("@Ad_email", txtemail.Text);
SqlParameter _outputparam = new SqlParameter();
_outputparam.ParameterName = "@Ad_Regid";
_outputparam.SqlDbType = System.Data.SqlDbType.VarChar;
_outputparam.Direction = System.Data.ParameterDirection.Output;
cmd.Parameters.Add(_outputparam);
cmd.ExecuteNonQuery(); **// Here shows my error:: String[7]: the Size property has an invalid size of 0.**
string _ID = _outputparam.Value.ToString();
ClientScript.RegisterStartupScript(this.GetType(), "message", "alert('New Values Inserted and Your temporary password is: " + _ID + "');", true);
MultiView1.SetActiveView(Login_stat);
}