熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET項目開發指南:房間類型的修改和刪除(2)[2]

2022-06-13   來源: .NET編程 

  程序  ST_RCatgEditModuleascxcs

    private void Submit_Click(object sender SystemEventArgs e)

    {

        if(PageIsValid )

        {

            //從文件WebConfig中讀取連接字符串

            string ST_sqldb =

    ConfigurationSettingsAppSettings[ConnectionString];

            //連接ST_GinShopManage數據庫

            SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

            ST_ConnOpen ()

            //定義SQL語句

            String updatesql=update ST_RoomCategory set

                ST_Name=@NameST_Area=@AreaST_BedNum=@BedNum

                ST_Price=@PriceST_AirCondition=@AirCondition

                ST_TV=@TV  where ST_RCategoryId = @RCategoryId;

            //利用Command對象調用updatesql

            SqlCommand ST_mycommand=new SqlCommand (updatesqlST_Conn)

            //向存儲過程中添加參數

            ST_mycommandParameters Add (@RCategoryIdSqlDbTypeInt)

            ST_mycommandParameters Add (@NameSqlDbTypeVarChar)

            ST_mycommandParameters Add (@AreaSqlDbTypeFloat)

            ST_mycommandParameters Add (@BedNumSqlDbTypeInt)

            ST_mycommandParameters Add (@PriceSqlDbTypeMoney)

            ST_mycommandParameters Add (@AirConditionSqlDbTypeInt)

            ST_mycommandParameters Add (@TVSqlDbTypeInt)

            //給存儲過程的參數賦值

            ST_mycommandParameters [@RCategoryId]Value

                =intParse(RCategoryIdLabelText)

            ST_mycommandParameters [@Name]Value

                =RCatgNameTextBoxTextTrim()

            ST_mycommandParameters [@Area]Value

                =ConvertToDouble(AreaTextBoxTextTrim())

            ST_mycommandParameters [@BedNum]Value

                =intParse(BedNumTextBoxTextTrim())

            ST_mycommandParameters [@Price]Value

                =ConvertToDouble(PriceTextBoxTextTrim())

            ST_mycommandParameters [@AirCondition]Value

                =AirConditionListSelectedIndex;

            ST_mycommandParameters [@TV]Value =TvListSelectedIndex;

            try

            {

                  //執行SQL語句並設置修改成功信息

                ST_mycommandExecuteNonQuery()

                ShowMsgText=房間類型信息修改成功;

                ShowMsgStyle[color]=green;}

            catch(SqlException error)

            {

                ShowMsgText=修改未成功請稍後再試原因+errorMessage;

                ShowMsgStyle[color]=red;

            }

            //關閉連接

            ST_ConnClose()

        }

    }

  【代碼說明】從代碼第~行可以看出創建了一些參數這些參數針對ST_RoomCategory表中的每一個字段然後在代碼第~行為這些參數賦值最後通過代碼第行執行SQL語句

  說明SqlException封裝的是訪問SQL Server時發生的錯誤

       返回目錄ASPNET項目開發指南

       編輯推薦

       ASPNET MVC 框架揭秘

       ASPNET開發寶典

       ASP NET開發培訓視頻教程

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15983.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.