工作我的提交按鈕動作:更新用但不能從UI
protected void submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=172.25.192.80;Initial Catalog=DB01HMS001;User ID=pj01hms001;Password=tcshyd");
con.Open();
SqlCommand cmd = new SqlCommand("usp_team5_customerupdate", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Title", Convert.ToString(DropDownList1.SelectedValue));
cmd.Parameters.AddWithValue("@Lastname",lstname.Text);
cmd.Parameters.AddWithValue("@StreetAddress", streetadd.Text);
cmd.Parameters.AddWithValue("@EmailAddress", Eaddress.Text);
cmd.Parameters.AddWithValue("@State", txtstate.Text);
cmd.Parameters.AddWithValue("@TownorCity",towncity.Text);
cmd.Parameters.AddWithValue("@Zipcode", Convert.ToInt32(txtzipcode.Text));
cmd.Parameters.AddWithValue("@MobileNumber",Convert.ToInt64(mblenum.Text));
cmd.Parameters.AddWithValue("@PhoneNumber", Convert.ToInt64(phnenum.Text));
cmd.Parameters.AddWithValue("@CompanyName", cname.Text);
cmd.Parameters.AddWithValue("@OfficeAddress", Oaddress.Text);
cmd.Parameters.AddWithValue("@custid", Convert.ToInt64(Session["cusid"]));
Response.Write(Convert.ToString(Session["cusid"]));
int a = cmd.ExecuteNonQuery();
if (a == 1) {
Response.Write("Success");
}
else
{
Response.Write("Failure");
}
con.Close();
}
我的表架構:
CREATE TABLE [dbo].[team5_customerprofile] (
[CustomerProfileID] INT IDENTITY (1001, 1) NOT NULL,
[CustomerID] AS (CONVERT([bigint],CONVERT([varchar],[CustomerProfileID],0)+CONVERT([varchar](15),getdate(),(112)),0)),
[Password] VARCHAR (20) NULL,
[Title] VARCHAR (20) NULL,
[Firstname] VARCHAR (20) NULL,
[Lastname] VARCHAR (20) NULL,
[DateOfBirth] DATE NULL,
[Gender] BIT NULL,
[StreetAddress] VARCHAR (100) NULL,
[Nationality] VARCHAR (20) NULL,
[State] VARCHAR (30) NULL,
[TownorCity] VARCHAR (50) NULL,
[Zipcode] INT NULL,
[MobileNumber] BIGINT NULL,
[AlternatePhone] BIGINT NULL,
[PhoneNumber] BIGINT NULL,
[EmailAddress] VARCHAR (30) NULL,
[CompanyName] VARCHAR (50) NULL,
[OfficeAddress] VARCHAR (100) NULL,
[TotalBonusMilesAcheived] INT DEFAULT ((0)) NULL,
CHECK ([Title]='Mrs.' OR [Title]='Miss.' OR [Title]='Mr.'),
CHECK ([Nationality]='Indian'),
CHECK (len([Zipcode])=(6))
);
我寫了一個存儲過程,如下圖所示,該更新表在外部執行它,但它不會更新表,當我嘗試通過用戶界面輸入值,然後按提交。
CREATE procedure usp_team5_customerupdate
(
@Title varchar(20),
@Lastname varchar(20),
@StreetAddress varchar(100),
@State varchar(30),
@TownorCity varchar(50),
@Zipcode int,
@MobileNumber bigint,
@PhoneNumber bigint,
@EmailAddress varchar(30),
@CompanyName varchar(50),
@OfficeAddress varchar(100),
@custid nvarchar(20)
)
as
begin
update team5_customerprofile
set
[email protected],[email protected],
[email protected],
[State][email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected],
[email protected]
where
[email protected]
end
你得到一個異常或錯誤? –
沒有例外,沒有錯誤。沒有。即使「ExecuteNonQuery()」返回1也表示查詢成功執行。 「成功」也正在顯示。即使在那之後,也沒有數據庫更新完成。 :( –
嘗試在您的更新語句周圍創建事務和提交事務。事務可能已關閉 –