小题目出现错误,帮忙解决下
本人正在做一个题目,是使用DataTable对象创建表student的结构并为表student添加新数据行,最后利用DataGrid控件显示到页面上
我写了以下代码,却运行不出来,请求哪个大师指点下,我是初学者呀
ublic partial class _Default : System.Web.UI.Page
{
System.Web.UI.WebControls.DataGrid myDG = new DataGrid();
protected void Page_Load(object sender, EventArgs e)
{
DataTable studentTable = new DataTable("student");
DataColumn S_id = new DataColumn();
S_id.DataType = System.Type.GetType("System.Int");
S_id.Caption = "学号";
S_id.ColumnName = "S_id";
DataColumn S_name = new DataColumn();
S_name.DataType = System.Type.GetType("System.Char(20)");
S_name.Caption = "姓名";
S_name.ColumnName = "S_name";
DataColumn Stature = new DataColumn();
Stature.DataType = System.Type.GetType("System.Int");
Stature.Caption = "身高";
Stature.ColumnName = "Stature";
DataSet myDS = new DataSet();
DataTable myTable = new DataTable();
myDS.Tables.Add(myTable);
DataColumn col1 = new DataColumn("S_id");
DataColumn col1 = new DataColumn("S_name");
DataColumn col1 = new DataColumn("Stature");
myTable.Columns.Add(col1);
myTable.Columns.Add(col2);
myTable.Columns.Add(col3);
DataRow newRow1 = myTable.NewRow();
newRow[0] = "1";
newRow[1] = "Andy";
newRow[2] = "165";
myTable.Rows.Add(newRow1);
DataRow newRow2 = myTable.NewRow();
newRow[0] = "2";
newRow[1] = "Bob";
newRow[2] = "175";
myTable.Rows.Add(newRow2);
DataRow newRow3 = myTable.NewRow();
newRow[0] = "3";
newRow[1] = "Davy";
newRow[2] = "173";
myTable.Rows.Add(newRow3);
myDG.DataSource = myDS;
myDG.DataBind();
this.Controls.Add(myDG);
}
}