AspnetPager的使用,新生相互交流,老手来给点意见
AspnetPager控件,我就不介绍了,个人感觉此分页控件还行,要是你有什么更好的分页控件,请告诉我!
首先,我先在数据库操作类中写几个函数:
第一个是不调用存储过程的:
public static DataSet Pager(int startIndex, int pageSize, string SQLString, string TableName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlDataAdapter da = new SqlDataAdapter(SQLString, connection))
{
DataSet ds = new DataSet();
try
{
connection.Open();
da.Fill(ds, startIndex, pageSize, TableName);
return ds;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
connection.Close();
}
}
}
}
接下来介绍个带存储过程的:
public static DataSet PagerControl(int startIndex, int pageSize, string SQLString, string TableName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlDataAdapter da = new SqlDataAdapter(SQLString, connection))
{
DataSet ds = new DataSet();
try
{
connection.Open();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.CommandText = SQLString;
da.Fill(ds, startIndex, pageSize, TableName);
return ds;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
connection.Close();
}
}
}
}
下面一个是查询专用的:
public static DataSet PagerControl(int startIndex, int pageSize, string SQLString, string TableName, params SqlParameter[] Params)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlDataAdapter da = new SqlDataAdapter(SQLString, connection))
{
DataSet ds = new DataSet();
try
{
connection.Open();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.CommandText = SQLString;
for (int i = 0; i <= Params.Length - 1; i++)
{
da.SelectCommand.Parameters.Add(Params[i]);
}
da.Fill(ds, startIndex, pageSize, TableName);
return ds;
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
finally
{
connection.Close();
}
}
}
}
浙公网安备 33010602011771号