aspnet调用mysql存储过程

来源:互联网 发布:淘宝装修设计教程 编辑:程序博客网 时间:2024/06/11 18:27
public static DataTable CommonPagenation(string tableName,string selectWhere,string selectID,string selectOrder,int pageNo,int pageSize,out int totalcount,out int pagecount)
{
DataTable reuslt = new DataTable();

using (MySqlConnection conn = new MySqlConnection(connectionString))
{
if (conn.State == ConnectionState.Closed)
conn.Open();

MySqlDataAdapter sda = new MySqlDataAdapter("CommonPagenation", conn);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
MySqlParameter[] param = new MySqlParameter[8];
param[0] = new MySqlParameter("?tableName", tableName);
param[1] = new MySqlParameter("?selectWhere", selectWhere);
param[2] = new MySqlParameter("?selectID", selectID);
param[3] = new MySqlParameter("?selectOrder", selectOrder);
param[4] = new MySqlParameter("?pageNo", pageNo);
param[5] = new MySqlParameter("?pageSize", pageSize);
param[6] = new MySqlParameter("?_totalcount",MySqlDbType.Int32);
param[6].Direction = ParameterDirection.Output;
param[7] = new MySqlParameter("?_pagecount", MySqlDbType.Int32);
param[7].Direction = ParameterDirection.Output;
sda.SelectCommand.Parameters.AddRange(param);
sda.Fill(reuslt);
totalcount = Convert.ToInt32(param[6].Value);
pagecount = Convert.ToInt32(param[7].Value);

}
return reuslt;

}

前台我是用的aspnetpager,非常好用的分页工具

 <webdiyer:AspNetPager ID="ItemPaging" runat="server" 
                CustomInfoSectionWidth="30%" PageSize="20" FirstPageText="首页" 
                LastPageText="最后一页" NextPageText="下一页" PrevPageText="上一页" 
                ShowCustomInfoSection="Left" CenterCurrentPageButton="True" LayoutType="Table" 
                ShowPageIndexBox="Never" OnPageChanging="ItemPaging_PageChanging">
            </webdiyer:AspNetPager>

调用::

DataTable table = DbHelperMySql.CommonPagenation("dede_archives", " typeid="+typeid, "", " dates desc ", ItemPaging.CurrentPageIndex, ItemPaging.PageSize,out totalcount,out pagecount);
            ItemPaging.RecordCount = totalcount;
            ItemPaging.AlwaysShow = true;
            ItemPaging.CustomInfoHTML = "总计<font color='blue'><b>" + ItemPaging.RecordCount.ToString() + "</b></font>条,";
            ItemPaging.CustomInfoHTML += "当前为第<font color='red'><b>" + ItemPaging.CurrentPageIndex.ToString() + "</b></font>页,";
            ItemPaging.CustomInfoHTML += "共<font color='blue'><b>" + ItemPaging.PageCount.ToString() + "</b></font>页";



0 0
原创粉丝点击