我想知道以下存储过程更新地址有什么问题(如果有的话): 我还给了我的数据库图像以获得一个清晰的想法......
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()中它确实采用了新值,但是当执行完成时,数据库没有更新......
答案 0 :(得分:2)
如果您通过加入表格UPDATE
直接怎么办?
UPDATE a
SET a.[auser_id] = b.ID,
a.[firstname] = @FirstName,
a.[lastname] = @LastName,
a.[country_id] = @Country_ID,
a.[addressline1] = @AddressLine1,
a.[addressline2] = @AddressLine2,
a.[addressline3] = @AddressLine3,
a.[telephone] = @Telephone,
a.[email] = @Email,
a.[city] = @City,
a.[state_id] = @State_ID,
a.[postalcode] = @PostalCode,
a.[mobile] = @Mobile
FROM [auseraddress] a
INNER JOIN AUser b
ON a.Email = b.Email
WHERE b.email = @OriginalEmail
答案 1 :(得分:0)
您的存储过程错误。
根据您的图片,AUserAddress表格不包含名为电子邮件的列。