C# dataset逐行讀取物件資料
阿新 • • 發佈:2019-01-09
List<Student> list = new List<Student>();
string sql = "select * from [Student$]";
DataSet ds = OleDBHelper.GetDataSet(sql,path);
DataTable dt = ds.Tables[0];
foreach (DataRow row in dt.Rows)
{
list.Add(new Student()
{
StudentName = row["姓名"].ToString(),
Gender=row["性別"].ToString(),
Birthday = Convert.ToDateTime(row["出生日期"]),
Age=DateTime.Now.Year- Convert.ToDateTime(row["出生日期"]).Year,
CardNo = row["考勤卡號"].ToString(),
StudentIdNo = row["身份證號"].ToString(),
PhoneNumber = row["電話號碼"].ToString(),
StudentAddress = row["家庭住址"].ToString(),
ClassId = Convert.ToInt32(row["班級編號"])
});
}
return list;
string sql = "select * from [Student$]";
DataSet ds = OleDBHelper.GetDataSet(sql,path);
DataTable dt = ds.Tables[0];
foreach (DataRow row in dt.Rows)
{
list.Add(new Student()
{
StudentName = row["姓名"].ToString(),
Gender=row["性別"].ToString(),
Birthday = Convert.ToDateTime(row["出生日期"]),
Age=DateTime.Now.Year- Convert.ToDateTime(row["出生日期"]).Year,
CardNo = row["考勤卡號"].ToString(),
StudentIdNo = row["身份證號"].ToString(),
PhoneNumber = row["電話號碼"].ToString(),
StudentAddress = row["家庭住址"].ToString(),
ClassId = Convert.ToInt32(row["班級編號"])
});
}
return list;