扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:马金虎 来源:yesky 2007年11月8日
关键字: Windows
public DataSet dataSet1 ; public SqlDataAdapter sqlDataAdapter1 ; |
private void Sort ( string sortString ) { SqlConnection sqlConnection1 = new SqlConnection ( "Server = localhost ; Database = NorthWind ; User ID = sa ; Password = ; " ) ; switch ( sortString ) { case "序号" : if ( blId ) { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 序号 ASC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blId = false ; } else { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 序号 DESC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blId = true ; } break ; case "姓氏" : if ( blLast ) { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 姓氏 ASC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blLast = false ; } else { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 姓氏 DESC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blLast = true ; } break ; case "名字" : if ( blFirst ) { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 名字 ASC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blFirst = false ; } else { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 名字 DESC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blFirst = true ; } break ; case "职务" : if ( blTitle ) { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 职务 ASC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blTitle = false ; } else { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 职务 DESC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blTitle = true ; } break ; case "生日" : if ( blBirth ) { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 生日 ASC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blBirth = false ; } else { sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter ( "SELECT EmployeeID as 序号, LastName as 姓氏 , FirstName as 名字 , Title as 职务 , Birthdate as 生日 From Employees ORDER BY 生日 DESC" , sqlConnection1 ) ; //以定义的数据库连接来初始化SqlDataAdapter实例 blBirth = true ; } break ; } dataSet1 = new DataSet ( ) ; sqlDataAdapter1.Fill ( dataSet1 , "employee" ) ; //以SqlDataAdapter实例来填充本地DataSet数据集 DataGrid1.DataSource = dataSet1 ; DataGrid1.DataBind ( ) ; //实现数据绑定 } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者