c# 中怎样动态创建数据表?
1个回答
推荐于2016-09-30
展开全部
DataSet dsClass=new DataSet();
DataTable dtClass=new DataTable("Class");
DataColumn id=new DataColumn("id",typeof(int));
DataColumn className=new DataColumn("className",typeof(string));
DataColumn gradeID=new DataColumn("gradeID",typeof(int));
dtClass.Columns.Add(id);
dtClass.Columns.Add(className);
dtClass.Columns.Add(gradeID); DataRow drClass=dtClass.NewRow();
drClass["className"]=this.txtClass.Text.Trim();
drClass["gradeID"]=gradeManager.GetGradeIDByGradeName(this.cboGrade.Text.Trim());
dtClass.Rows.Add(drClass);
dsClass.Tables.Add(dtClass);
DataTable dtClass=new DataTable("Class");
DataColumn id=new DataColumn("id",typeof(int));
DataColumn className=new DataColumn("className",typeof(string));
DataColumn gradeID=new DataColumn("gradeID",typeof(int));
dtClass.Columns.Add(id);
dtClass.Columns.Add(className);
dtClass.Columns.Add(gradeID); DataRow drClass=dtClass.NewRow();
drClass["className"]=this.txtClass.Text.Trim();
drClass["gradeID"]=gradeManager.GetGradeIDByGradeName(this.cboGrade.Text.Trim());
dtClass.Rows.Add(drClass);
dsClass.Tables.Add(dtClass);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询