asp.net api后台

public string sqlstr = ConfigurationManager.ConnectionStrings["LIANJIE"].ConnectionString;
DBhelper db = new DBhelper();
//存储过程显示
public DataTable DateShow(string TableName,string WhereName,string OrderBy,int PageIndex,int PageSize, out int PageCount )
{
SqlParameter[] parameters = new SqlParameter[] {
new SqlParameter(){ ParameterName="tableNanme",SqlDbType= SqlDbType.Text,Value=TableName},
new SqlParameter(){ ParameterName="whereName",SqlDbType= SqlDbType.Text,Value=WhereName},
new SqlParameter(){ ParameterName="orderBy",SqlDbType= SqlDbType.Text,Value=OrderBy},
new SqlParameter(){ ParameterName="pageIndex",SqlDbType= SqlDbType.Int,Value=PageIndex},
new SqlParameter(){ ParameterName="pageSize",SqlDbType= SqlDbType.Int,Value=PageSize},
new SqlParameter(){ ParameterName="pageCount",SqlDbType= SqlDbType.Int,Direction= ParameterDirection.Output},
};
using (SqlConnection con=new SqlConnection(sqlstr))
{
con.Open();
using (SqlCommand com = new SqlCommand("pageStu",con))
{
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddRange(parameters);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(com);
DataTable tb = new DataTable();
sqlDataAdapter.Fill(tb);
PageCount = Convert.ToInt32( parameters[5].Value);
return tb;
}
}
}

posted @ 2020-06-10 09:58  孔捷  阅读(144)  评论(0编辑  收藏  举报