急急急~~~
/// <summary>
/// 产品分页展示根据ClassName
/// </summary>
/// <param name="pagesize">每页显示多少条</param>
/// <param name="pageindex">当前第几页</param>
/// <returns>返回List<prod_news>集合</returns>
public List<prod_news> ProductFenYeByClassName(int pagesize, int pageindex,string className)
{
try
{
int num = pagesize * pageindex;
string sqlStr = "select top 12 * from prod_news where ID not in (select top " + num + " ID from prod_news order by infotime desc) and ClassName=@ClassName order by infotime desc";
OleDbCommand cmd = new OleDbCommand(sqlStr, con);
OleDbParameter par1 = new OleDbParameter("@pagesize", OleDbType.Integer);
OleDbParameter par2 = new OleDbParameter("@pageindex", OleDbType.Integer);
OleDbParameter par3=new OleDbParameter("@ClassName",OleDbType.VarChar);
par1.Value = pagesize;
par2.Value = pageindex;
par3.Value=className;
cmd.Parameters.Add(par1);
cmd.Parameters.Add(par2);
cmd.Parameters.Add(par3);
List<prod_news> list = new List<prod_news>();
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
prod_news prod_news = new prod_news();
prod_news.ID = Convert.ToInt32(reader["ID"]);
prod_news.title = reader["title"].ToString();
prod_news.content = reader["content"].ToString();
//prod_news.ClassName = reader["ClassName"].ToString();
prod_news.img = reader["img"].ToString();
prod_news.okay2 = Convert.ToInt32(reader["okay2"]);
prod_news.okay = Convert.ToInt32(reader["okay"]);
prod_news.infotime = Convert.ToDateTime(reader["infotime"]);
prod_news.hits = Convert.ToInt32(reader["hits"]);
prod_news.ok = Convert.ToBoolean(reader["ok"]);
list.Add(prod_news);
}
return list;
}
catch (Exception ec)
{
throw ec;
}
finally
{
con.Close();
}
}
请问我这个SQL写的有问题吗?
是ACCESS数据库
为什么每次跳过如下代码 while (reader.Read())
{
prod_news prod_news = new prod_news();
prod_news.ID = Convert.ToInt32(reader["ID"]);
prod_news.title = reader["title"].ToString();
prod_news.content = reader["content"].ToString();
//prod_news.ClassName = reader["ClassName"].ToString();
prod_news.img = reader["img"].ToString();
prod_news.okay2 = Convert.ToInt32(reader["okay2"]);
prod_news.okay = Convert.ToInt32(reader["okay"]);
prod_news.infotime = Convert.ToDateTime(reader["infotime"]);
prod_news.hits = Convert.ToInt32(reader["hits"]);
prod_news.ok = Convert.ToBoolean(reader["ok"]);
list.Add(prod_news);
}
直接 return list;了呢,
[解决办法]
string sqlStr = "select top 12 * from prod_news where ID not in (select top " + num + " ID from prod_news order by infotime desc) and ClassName=@ClassName order by infotime desc";