我有一个网站,其中一个表格将显示资产列表及其信息从sql中的表中提取。我有一个部分按钮,如果有必要,职员可以通过在文本或下拉字段中输入新信息来按下和修改现有信息。这是使用存储过程完成的;一切似乎运行良好,直到你检查工作,没有任何更新!
以下是编辑信息的代码;
protected void ADD_Click(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["DATASYSTEMS"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("UPDATING_ASSETS", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ASSET_NUMBER", Txtasset_number.Text);
cmd.Parameters.AddWithValue("@MACHINE_NAME", Txtmachine_name.Text);
cmd.Parameters.AddWithValue("@PORT_NUMBER", Txtport_number.Text);
cmd.Parameters.AddWithValue("@BUILDING_NUMBER", DPBUILDING.SelectedValue);
cmd.Parameters.AddWithValue("@ROOM_NUMBER", Txtroom_number.Text);
cmd.Parameters.AddWithValue("@TELEPHONE_NUMBER", Txttelephone_number.Text);
cmd.Parameters.AddWithValue("@FLOOR", Txtfloor.Text);
cmd.Parameters.AddWithValue("@SERIAL", Txtserial.Text);
cmd.Parameters.AddWithValue("@TYPE", DPTYPE.SelectedValue);
cmd.Parameters.AddWithValue("@BRANCH", DPBRANCH.SelectedValue);
cmd.Parameters.AddWithValue("@SECTION", DPSECTION.SelectedValue);
cmd.Parameters.AddWithValue("@USERS", txtuser1.Text);
ClientScript.RegisterClientScriptBlock(this.GetType(), "key", "<script type='text/javascript'>alert('Record has been updated.');window.location='navigation.aspx';</script>");
}
}
protected void dglocaltables_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
这是应该更新的存储过程。
CREATE PROCEDURE [dbo].[update_TBL_INFO_1] @ASSET_NUMBER as nvarchar(50), @PORT_NUMBER as nvarchar(50), @MACHINE_NAME as nvarchar(50), @TYPE as nvarchar(50) , @BRANCH as nvarchar(50), @SECTION as nvarchar(50), @BUILDING_NUMBER as nvarchar(50), @ROOM_NUMBER as nvarchar(50), @TELEPHONE_NUMBER as nvarchar (50), @FLOOR as nvarchar (50), @USERS as nvarchar (50), @ID as float (8), @SERIAL as nvarchar (50) as
If (SELECT ASSET_NUMBER FROM dbo.TBL_INFO WHERE ASSET_NUMBER=@ASSET_NUMBER AND [ID]=@ID)=@ASSET_NUMBER
BEGIN
If (SELECT MACHINE_NAME FROM dbo.TBL_INFO WHERE MACHINE_NAME=@MACHINE_NAME AND [ID]=@ID)=@MACHINE_NAME
BEGIN
If (SELECT PORT_NUMBER FROM dbo.TBL_INFO WHERE PORT_NUMBER=@PORT_NUMBER AND [ID]=@ID)=@PORT_NUMBER
BEGIN
If (SELECT [ID] FROM dbo.TBL_INFO WHERE [ID]=@ID)=@ID
BEGIN
UPDATE dbo.TBL_INFO
SET
dbo.TBL_INFO.ASSET_NUMBER = @ASSET_NUMBER,
dbo.TBL_INFO.MACHINE_NAME = @MACHINE_NAME,
dbo.TBL_INFO.PORT_NUMBER = @PORT_NUMBER,
dbo.TBL_INFO.BUILDING_NUMBER = @BUILDING_NUMBER,
dbo.TBL_INFO.ROOM_NUMBER = @ROOM_NUMBER,
dbo.TBL_INFO.TELEPHONE_NUMBER = @TELEPHONE_NUMBER,
dbo.TBL_INFO.[FLOOR]= @FLOOR,
dbo.TBL_INFO.TYPE = @TYPE,
dbo.TBL_INFO.BRANCH = @BRANCH,
dbo.TBL_INFO.[SECTION] = @SECTION,
dbo.TBL_INFO.USERS = @USERS,
dbo.TBL_INFO.[ID] = @ID,
dbo.TBL_INFO.SERIAL = @SERIAL
WHERE dbo.TBL_INFO.ASSET_NUMBER=@ASSET_NUMBER
INSERT INTO dbo.TBL_INFO (ASSET_NUMBER, MACHINE_NAME, PORT_NUMBER, BUILDING_NUMBER, ROOM_NUMBER, TELEPHONE_NUMBER, [FLOOR], TYPE, BRANCH, [SECTION], USERS, SERIAL, [ID]) VALUES (@ASSET_NUMBER, @MACHINE_NAME, @PORT_NUMBER, @BUILDING_NUMBER, @ROOM_NUMBER, @TELEPHONE_NUMBER, @FLOOR, @TYPE, @BRANCH, @SECTION, @USERS, @SERIAL, @ID)
SELECT @ID, ACCESS='VALID'
END
ELSE
BEGIN
SELECT @ID, ACCESS='INVALID'
END
END
ELSE
BEGIN
SELECT ACCESS='RESTRICTED'
END
END
ELSE
BEGIN
SELECT ACCESS='DENIED'
END
END
GO
我哪里错了?
答案 0 :(得分:3)
您永远不会执行命令!
你需要在所有那些.AddWithValue()调用结束时使用它:
cmd.ExecuteNonQuery();