请把这个函数的每个语句详细的解释一下
publicList<tbGuestBook>QueryMessage(){List<tbGuestBook>list=newList<tbGuestBook>();DA...
public List<tbGuestBook> QueryMessage()
{
List<tbGuestBook> list = new List<tbGuestBook>();
DAL.SqlServer da = new DAL.SqlServer();
DataTable dt = da.QueryMessage().Table[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
tbGuestBook gb = new tbGuestBook();
gb.ID = new Guid(dr["ID"].ToString());
gb.UserName = dr["UserName"].ToString();
gb.Message = dr["Message"].ToString();
gb.PostTime = Convert.ToDateTime(dr["PostTime"]);
gb.IsReplied = dr["IsReplied"].ToString() == "1";
gb.Reply = dr["Reply"].ToString();
list.Add(gb);
}
return list;
} 展开
{
List<tbGuestBook> list = new List<tbGuestBook>();
DAL.SqlServer da = new DAL.SqlServer();
DataTable dt = da.QueryMessage().Table[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
tbGuestBook gb = new tbGuestBook();
gb.ID = new Guid(dr["ID"].ToString());
gb.UserName = dr["UserName"].ToString();
gb.Message = dr["Message"].ToString();
gb.PostTime = Convert.ToDateTime(dr["PostTime"]);
gb.IsReplied = dr["IsReplied"].ToString() == "1";
gb.Reply = dr["Reply"].ToString();
list.Add(gb);
}
return list;
} 展开
2个回答
展开全部
public List<tbGuestBook> QueryMessage()
{
List<tbGuestBook> list = new List<tbGuestBook>();//创建一个tbGustBook类型的List容器
DAL.SqlServer da = new DAL.SqlServer();//这个应该是封装的一个数据库访问类
DataTable dt = da.QueryMessage().Table[0];//获取查询到结果的表
for (int i = 0; i < dt.Rows.Count; i++)//循环
{
DataRow dr = dt.Rows[i];//获取弟i列
tbGuestBook gb = new tbGuestBook();//新创建一个tbGuestBook类的实例
gb.ID = new Guid(dr["ID"].ToString());//设置该类的ID
gb.UserName = dr["UserName"].ToString();//设置该类的UserName
gb.Message = dr["Message"].ToString();//设置该类的Message
gb.PostTime = Convert.ToDateTime(dr["PostTime"]);//设置该类的PostTime
gb.IsReplied = dr["IsReplied"].ToString() == "1";//设置该类的IsReplied
gb.Reply = dr["Reply"].ToString();//设置该类的Reply
list.Add(gb);//将类添加的容器中
}
return list;//返回List容器
}
{
List<tbGuestBook> list = new List<tbGuestBook>();//创建一个tbGustBook类型的List容器
DAL.SqlServer da = new DAL.SqlServer();//这个应该是封装的一个数据库访问类
DataTable dt = da.QueryMessage().Table[0];//获取查询到结果的表
for (int i = 0; i < dt.Rows.Count; i++)//循环
{
DataRow dr = dt.Rows[i];//获取弟i列
tbGuestBook gb = new tbGuestBook();//新创建一个tbGuestBook类的实例
gb.ID = new Guid(dr["ID"].ToString());//设置该类的ID
gb.UserName = dr["UserName"].ToString();//设置该类的UserName
gb.Message = dr["Message"].ToString();//设置该类的Message
gb.PostTime = Convert.ToDateTime(dr["PostTime"]);//设置该类的PostTime
gb.IsReplied = dr["IsReplied"].ToString() == "1";//设置该类的IsReplied
gb.Reply = dr["Reply"].ToString();//设置该类的Reply
list.Add(gb);//将类添加的容器中
}
return list;//返回List容器
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询