晕的不总结不行,在阴沟中翻第二次船,不知道是不是自己笨,下午这个问题上浪费了时间,身边没以前的代码,注意实体类定义ArticleInfo model = new ArticleInfo();要放到while (dataReader.Read()),而不是using()下,更不是using外面,而list items是放到using()外面,好记性不如烂笔头,记记,下次要长长脑子
Code
public IList<ArticleInfo> GetArticle(string classid)
{
IList<ArticleInfo> items = new List<Article>();
DbParameter[] parms = { DbHelper.MakeInParam("@classid", (DbType)
SqlDbType.VarChar, 8, _classid) };
using (IDataReader dataReader = DbHelper.ExecuteReader
(CommandType.StoredProcedure, "getArticlemodel", parms))
{
while (dataReader .Read())
{
ArticleInfo model = new ArticleInfo();
model.ID = rdr.GetInt32(0);
model.Title = rdr.GetString(1);
model.Content = rdr.GetString(2);
items.Add(model);
}
}
return items;
}