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 ( ) ;
//实现数据绑定
}