事件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开发培训视频教程
[] []