1.代码
DatabaseHelp.processDetailTableAdapter.FillByWeekReturnLatestID(dt, DateTime.Now.AddDays(-7), DateTime.Now);
DataTable DT = dt as DataTable;
if (DT.Rows.Count > 0)
{
// 原
//DataRow lastRow = DT.Rows[DT.Rows.Count - 1];
//var detailLastID = UserMath.ToInt32(lastRow["ID"].ToString());
DataRow latestRow = DT.AsEnumerable()
.OrderByDescending(row => row.Field<DateTime>("UpdateTime"))
.FirstOrDefault();
var detailLastID = UserMath.ToInt32(latestRow["ID"].ToString());
}
2.获取DataTable任意列数据
string sql1 = $" SELECT Pwd FROM Userinfo where UserName=‘{UserName}’ AND IsDeleted=0";
DataTable dt= SqlHelper.GetDataTableBySql(sql1);//根据sql查出表
string rPwd = dt.Rows[0][“Pwd”].ToString();//取查出的第一行数据中,密码列的数据
小结:
网上查询关于DataTable类型数据查询所使用LINQ较少,记录一下