自定义DateTable样例

记录流程备查
 #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)