房間使用信息的查詢
當管理員單擊查詢按鈕時將觸發search_Click事件讀取查詢按鈕前邊下拉列表框中的內容並將其作為條件對數據庫進行查詢然後再將查詢出的結果綁定到dl_RoomsList該事件的部分代碼如程序所示
程序 ST_RBusiManModuleascxcs
…
private void search_Click(object sender SystemEventArgs e)
{
if(dl_RoomsListSelectedIndex>)
{
dl_RoomsListSelectedIndex=;
}
//從文件WebConfig中讀取連接字符串
string ST_sqldb =
ConfigurationSettingsAppSettings[ConnectionString];
//連接ST_GinShopManage數據庫
SqlConnection ST_Conn = new SqlConnection(ST_sqldb)
//創建SqlDataAdapter對象調用存儲過程ST_ShowRoomsInfo
SqlDataAdapter ST_myadapter = new SqlDataAdapter
(ST_ShowRoomByCatgAndStatusST_Conn)
ST_myadapterSelectCommandCommandType =CommandTypeStoredProcedure;
ST_myadapterSelectCommandParameters Add
(@RCategoryIdSqlDbTypeInt)
ST_myadapterSelectCommandParameters [@RCategoryId]Value
=RCategoryNameListSelectedIndex;
ST_myadapterSelectCommandParameters Add
(@StatusSqlDbTypeInt)
ST_myadapterSelectCommandParameters [@Status]Value
=StatusListSelectedIndex;
//創建並填充DataSet
DataSet ds = new DataSet ()
ST_myadapterFill (ds)
dl_RoomsListDataSource =ds;
dl_RoomsListDataBind ()
//根據房間狀態確定dl_RoomsList的Status顯示
for(int i=;i<dl_RoomsListItemsCount;i++)
{
DataRow dr=dsTables[]Rows[i];
if(dr[ST_Status]ToString()==)
{
((Label)dl_RoomsListItems[i]
FindControl(StatusLabel))Text=否;
}
else if(dr[ST_Status]ToString()==)
{
((Label)dl_RoomsListItems[i]
FindControl(StatusLabel))Text=有;
}
}
ST_ConnClose ()
}
private void ShowAll_Click(object sender SystemEventArgs e)
{
//dl_RoomsList顯示房間信息
Show_RoomsList()
}
…
【代碼說明】代碼第~行表示這是一個使用存儲過程完成的查詢使用的存儲過程名為ST_ShowRoomByCatgAndStatus查詢後將結果綁定到dl_RoomsList控件上
說明dl_RoomsListSelectedIndex如果等於則表示沒有選擇任何選項
[] []
From:http://tw.wingwit.com/Article/program/net/201311/15968.html