客户信息查询()
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代码第~行是查询语句代码第~行实现数据到控件的绑定
[] []