mysql c#分页通过存储过程和out参数同时获得总数和表
return SQLHelper.ExecuteReaderAndCount(SQLHelper.ConnectioinString, CommandType.StoredProcedure, "call GetMediaInfoNewNoApprove(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,@count)", out count,getMediaByRd, par);
/// <summary> /// 带总数量的查询 /// </summary> /// <param name="connectionString"></param> /// <param name="cmdType"></param> /// <param name="cmdText"></param> /// <param name="commandParameters"></param> /// <returns></returns> public static DataTable ExecuteReaderAndCount(string connectionString, CommandType cmdType, string cmdText, out int count,gettablebyRd gettable, params OdbcParameter[] commandParameters) { OdbcCommand cmd = new OdbcCommand(); OdbcConnection conn = new OdbcConnection(connectionString);
// we use a try/catch here because if the method throws an exception we want to // close the connection throw code, because no datareader will exist, hence the // commandBehaviour.CloseConnection will not work try { count = 0; PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
OdbcParameter _p = new OdbcParameter("@count",OdbcType.Int); _p.Direction = ParameterDirection.Output; cmd.Parameters.Add(_p); OdbcDataReader rdr = cmd.ExecuteReader(); DataTable dt= gettable(rdr); cmd.CommandText = "select @count"; count = int.Parse(cmd.ExecuteScalar().ToString()); cmd.Parameters.Clear(); return dt; } catch { count = 0; conn.Close(); throw; }
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。