我想知道以下用于更新地址的存储过程有什么问题(如果有的话):我还给出了我的数据库图像以获得清晰的想法......
ALTER PROCEDURE [dbo].[usp_UpdateAddress]
(@OriginalEmail nvarchar(50), @FirstName varchar(50), @LastName varchar(50),
@Country_ID int, @AddressLine1 varchar(50), @AddressLine2 varchar(50),
@AddressLine3 varchar(50), @Telephone varchar(50), @Email nvarchar(50),
@City varchar(50), @State_ID int, @PostalCode varchar(50), @Mobile varchar(50))
AS
BEGIN
DECLARE @User_ID INT
SELECT @User_ID = ID FROM AUser Where Email = @OriginalEmail
UPDATE [AUserAddress]
SET [AUser_ID] = @User_ID, [FirstName] = @FirstName, [LastName] = @LastName,
[Country_ID] = @Country_ID, [AddressLine1] = @AddressLine1,
[AddressLine2] = @AddressLine2, [AddressLine3] = @AddressLine3,
[Telephone] = @Telephone, [Email] = @Email, [City] = @City,
[State_ID] = @State_ID, [PostalCode] = @PostalCode, [Mobile] = @Mobile
WHERE
Email = @OriginalEmail
END
从 C# 调用:
private void UpdateAddress()
{
try
{
string strSession = objGetSession.GetEmailFromSession();
con.Open();
SqlCommand sqlCmd = new SqlCommand("usp_UpdateAddress", con);
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.Add("@OriginalEmail ", SqlDbType.NVarChar, 50).Value = strSession;
sqlCmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Value = txtFirstName.Text;
sqlCmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50).Value = txtLastName.Text;
sqlCmd.Parameters.Add("@AddressLine1", SqlDbType.VarChar, 50).Value = txtAddressLine1.Text;
sqlCmd.Parameters.Add("@AddressLine2", SqlDbType.VarChar, 50).Value = txtAddressLine2.Text;
sqlCmd.Parameters.Add("@AddressLine3", SqlDbType.VarChar, 50).Value = txtAddressLine3.Text;
sqlCmd.Parameters.Add("@Telephone", SqlDbType.VarChar, 50).Value = txtTelephone.Text;
sqlCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50).Value = txtEmailAddress.Text;
sqlCmd.Parameters.Add("@Country_ID", SqlDbType.Int).Value = ddlCountry.SelectedItem.Value;
sqlCmd.Parameters.Add("@City", SqlDbType.VarChar, 50).Value = txtCity.Text;
sqlCmd.Parameters.Add("@State_ID", SqlDbType.Int).Value = ddlState.SelectedValue.ToString();
sqlCmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 50).Value = txtPostalCode.Text;
sqlCmd.Parameters.Add("@Mobile", SqlDbType.VarChar, 50).Value = txtMobile.Text;
sqlCmd.Connection = con;
sqlCmd.ExecuteNonQuery();
con.Close();
mpeTest.Show();
Response.Write("<script> alert('Address Updated!') </script>");
}
catch (Exception e)
{
Response.Write("An Error Occurred" + e);
}
}
存储过程没有执行吗?调试显示在 Update Address() 中它确实采用了新值,但是执行完成后,数据库没有更新......