MySqlParameter 传参问题
GetList 方法一直获取不到数据,假如直接写sql可以查询到数据,个人怀疑是PrepareCommand 传参的时候没有跟sql字段关联起来,但是从网上找的demo都是这样传参的,求解决,急!!!
public DataSet GetList(string strWhere, string orderby, int page, int pageSize)
{//在哪
StringBuilder strSql = new StringBuilder();
strSql.Append("select MenuID,MenuName,MenuUrl,MenuIco,MenuFatherID,IsSubset,OrderbyCode,IsDisplay from menuinfo");
strSql.AppendFormat(" where ?strWhere");
strSql.Append(" order by ?orderby limit ?pagecount,?pagesize;");
strSql.AppendFormat("select count(*) from menuinfo where ?strWhere");
MySqlParameter[] parameters = {
new MySqlParameter("?strWhere", MySqlDbType.VarChar, 255),
new MySqlParameter("?orderby",MySqlDbType.VarChar,255),
new MySqlParameter("?pagecount",MySqlDbType.Int32,4),
new MySqlParameter("?pagesize",MySqlDbType.Int32,4)
};
parameters[0].Value = strWhere;
parameters[1].Value = orderby;
parameters[2].Value = (page - 1) * pageSize;
parameters[3].Value = pageSize;
DataSet ds = new DataSet();
ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
return ds;
}
public static DataSet Query(string sql, MySqlParameter[] param)
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
PrepareCommand(cmd, connection, nu