日期:2014-05-18 浏览次数:20646 次
Dealer dl = new Dealer(); using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "searchOnDealer", new SqlParameter("@ID", dID))) { if (dr.HasRows) { dl.ID = dr.GetInt32(0); dl.Name = dr.GetString(1); dl.Address = dr.GetString(2); dl.Theme = dr.GetInt32(5); } }
while(reader.Read()) { dl.ID = reader.GetInt32(0); dl.Name = reader.GetString(1); dl.Address = reader.GetString(2); dl.Theme = reader.GetInt32(5); }
------解决方案--------------------
if (dr.HasRows && dr.Read())
{
int id=0;
int.TryPase(dr["字段名1"].ToString();,out id);
dl.ID=id;
dl.Name = dr["字段名2"].ToString();
dl.Address = dr["字段名3"].ToString();
int theme=0;
int.TryPase(dr["字段名5"].ToString();,out theme);
dl.Theme =theme; //如果确定数据没有问题,就用Parse()
}