1. DataTable 类对象表示一个内存中数据表。可以用来存放从数据库得到的DataSet。
DataTable dt = SqlHelper.ExecuteDataTable(parameter )
2. 有的时候需要的dt中会包含很多数据下面会提到,但是有的时候我们会定位到某个特定的结果,即查询的结果有且只有一个
使用dt.Rows.Count来判断查询的结果行数, 最后将改行结果存放到DataRow 的row 对象中
if (dt.Rows.Count <= )
{
return null;
}
else if (dt.Rows.Count > )
{
throw new Exception("More than one data");
}
else
{
DataRow row = dt.Rows[]; Customer cust = new Customer();
cust.Id = (long)row["id"];
cust.Name = (string)row["Name"];
cust.BirthDay =
(DateTime?)SqlHelper.FromDbValue(row["BirthDay"]);
cust.Address = (string)row["address"];
cust.CustLevel = (int)row["CustLevel"];
cust.TelNum = (string)row["TelNum"];
return cust;
}