2013-02-01 77 views
0

我有一個網站,其中一個表格將顯示資產列表和他們的信息從SQL中的表中拉出。如果有必要,我有一個部分按鈕,一個職員可以通過在文本或下拉字段中輸入新內容來按下和修改現有信息。這是使用存儲過程完成的;一切似乎運行良好,直到你檢查工作,沒有任何更新!存儲過程不更新在asp.net觸發的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 [email protected]_NUMBER AND [ID][email protected])[email protected]_NUMBER 
BEGIN 
    If (SELECT MACHINE_NAME FROM dbo.TBL_INFO WHERE [email protected]_NAME AND [ID][email protected])[email protected]_NAME 
    BEGIN 
     If (SELECT PORT_NUMBER FROM dbo.TBL_INFO WHERE [email protected]_NUMBER AND [ID][email protected])[email protected]_NUMBER 
     BEGIN 
      If (SELECT [ID] FROM dbo.TBL_INFO WHERE [ID][email protected])[email protected] 
      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 [email protected]_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

我要去哪裏錯了?

+2

您所標記的問題vb.net,但代碼是C#? –

回答

3

您從不執行命令!

你在所有的結尾需要這個的.AddWithValue()調用:

cmd.ExecuteNonQuery();