欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自定义DateTable样例

程序员文章站 2022-03-20 13:58:03
...
[size=large][color=green]记录流程备查[/color][/size]

#region 创建自定义DataTable
DataTable dt = new DataTable("downQuestion");
DataColumn dcQuestionID = new DataColumn("QuestionID",typeof(int));
DataColumn dcContentType = new DataColumn("ContentType",typeof(string));
DataColumn dcCompanyName = new DataColumn("CompanyName",typeof(string));
DataColumn dcQuestionContent = new DataColumn("QuestionContent",typeof(string));
DataColumn dcCreateTime = new DataColumn("CreateTime", typeof(DateTime));
DataColumn dcIsDisplay = new DataColumn("IsDisplay", typeof(bool));
DataColumn dcIsReply = new DataColumn("IsReply", typeof(bool));
DataColumn dcQuestionUserName = new DataColumn("QuestionUserName", typeof(string));
DataColumn dcQuestionRealname = new DataColumn("Realname", typeof(string));
DataColumn dcAnswerUserName = new DataColumn("AnswerUserName", typeof(string));

dt.Columns.Add(dcQuestionID);
dt.Columns.Add(dcContentType);
dt.Columns.Add(dcCompanyName);
dt.Columns.Add(dcQuestionContent);
dt.Columns.Add(dcCreateTime);
dt.Columns.Add(dcIsDisplay);
dt.Columns.Add(dcIsReply);
dt.Columns.Add(dcQuestionUserName);
dt.Columns.Add(dcQuestionRealname);
dt.Columns.Add(dcAnswerUserName);
#endregion

#region 循环填入数据
for (int i = 0; i < questionTable.Rows.Count;i++ )
{
//问题
DataRow qdr = dt.NewRow();
qdr["QuestionID"] = questionTable.Rows[i]["ID"];
qdr["ContentType"] = questionTable.Rows[i]["ContentType"];
qdr["CompanyName"] = questionTable.Rows[i]["CompanyName"];
qdr["QuestionContent"] = questionTable.Rows[i]["QuestionContent"];
qdr["CreateTime"] = questionTable.Rows[i]["CreateTime"];
qdr["IsDisplay"] = questionTable.Rows[i]["IsDisplay"];
qdr["IsReply"] = questionTable.Rows[i]["IsReply"];
qdr["QuestionUserName"] = questionTable.Rows[i]["UserName"];
qdr["Realname"] = questionTable.Rows[i]["Realname"];
//qdr["AnswerUserName"] = questionTable.Rows[i]["AnswerUserName"];
dt.Rows.Add(qdr);
}
#endregion
相关标签: .net