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

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

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

    客戶信息查詢(

  ST_CustomersManModuleascxcs的主要代碼及其解釋

  ST_CustomersManModuleascxcs是查詢控件的後台文件當頁面加載時會執行Page_Load中的代碼這裡執行的是一個自定義的方法Show_CustomersList()其代碼如程序所示

  程序  ST_CustomersManModuleascxcs

    public partial class ST_CustomersManModule : ST_ModuleBase

    {

        private void Page_Load(object sender SystemEventArgs e)

        {

            if(!IsPostBack)

                Show_CustomersList()

        }

        protected void Show_CustomersList()

        {

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

            string ST_sqldb =

            ConfigurationSettingsAppSettings[ConnectionString];

            //連接ST_GinShopManage數據庫

            SqlConnection ST_Conn = new SqlConnection (ST_sqldb)

            //定義SQL語句

            String ST_selsql=select cST_CNamecST_CIdentityId

            rST_RoomIdrST_BeginTimedST_EndTimecST_CPhone

  

            + from ST_RoomOperation r inner join ST_CustomersInfo c on

                cST_CIdentityId=rST_CIdentityId

                + left outer join ST_History d on

                cST_CIdentityId=dST_CIdentityId;

            //創建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 ()

        }

        protected void GridView_Page(Object sender

                GridViewPageEventArgs E)

        {

            dg_CustomersList PageIndex =ENewPageIndex ;

            Show_CustomersList()

        }

        private void ShowAll_Click(object sender SystemEventArgs e)

        {

            Show_CustomersList()

        }

    …  …

  【代碼說明】本段代碼主要是從數據庫中讀取數據並綁定到dg_CustomersList代碼第~行是查詢語句代碼第~行實現數據到控件的綁定

[]  []  


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