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

ASP.NET項目開發指南:客戶信息查詢(2)[2]

2013-11-13 12:28:01  來源: .NET編程 

  事件search_Click是最主要的操作它將頁面中各個需要的控件作為條件加入到SQL語句然後進行查詢再把數據顯示出來該事件的主要代碼如程序所示

  程序  ST_ CustomersManModuleascxcs

        …

    private void search_Click(object sender SystemEventArgs e)

    {

        dg_CustomersListCurrentPageIndex=;

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

        string ST_sqldb =

            ConfigurationSettingsAppSettings[ConnectionString];

        //連接ST_GinShopManage數據庫

        SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

        //定義SQL語句

        String ST_selsql=select cST_CNamecST_CIdentityId

            rST_RoomId + rST_BeginTimecST_CPhone

            from ST_RoomOperation rST_CustomersInfo c where

            cST_CIdentityId=rST_CIdentityId;

        //讀取時間記錄

        string ST_datefrom=YearFromListSelectedItemValueToString()

            ++MouthFromListSelectedItemValueToString()

            ++DayFromListSelectedItemValueToString()

  

        string ST_dateto=YearToListSelectedItemValueToString()

             ++MouthToListSelectedItemValueToString()

            ++DayToListSelectedItemValueToString()

        ST_selsqlST_selsql=ST_selsql+ and rST_BeginTime between

            +ST_datefrom+and+ST_dateto+;

        //讀取方式記錄

        if(InputTextBoxText!=

        {

            //按姓名

            if(StatusListSelectedIndex==

                ST_selsqlST_selsql=ST_selsql+ and

            cST_CName=+InputTextBoxTextTrim()+;

            //按身份證號

            else if(StatusListSelectedIndex==

                ST_selsqlST_selsql=ST_selsql+ and

                cST_CIdentityId=+InputTextBoxTextTrim()+;

        }

        //創建SqlDataAdapter對象調用ST_selsql

        SqlDataAdapter ST_myadapter = new SqlDataAdapter

            (ST_selsqlST_Conn)

        //創建並填充DataSet

        DataSet ST_ds = new DataSet ()

        ST_myadapterFill (ST_ds)

        dg_CustomersListDataSource =ST_ds;

        dg_CustomersListDataBind ()

        ST_ConnClose ()

    }

  【代碼說明】上述代碼中的第~行是查詢條件~行是查詢的時間段~行是設置查詢方式~行是查詢數據並將其綁定到網格中

  說明YearToListSelectedItemValue是選擇列表的值而YearToListSelectedItemText是顯示列表的選項

       返回目錄ASPNET項目開發指南

       編輯推薦

       ASPNET MVC 框架揭秘

       ASPNET開發寶典

       ASP NET開發培訓視頻教程

[]  []  


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