运行时错误找不到列0.下面是我的代码
string connectiostring = (string)ConfigurationSettings.AppSettings["NorthwindConnectionString"]; SqlConnection conn = new SqlConnection(connectiostring); SqlCommand cmd = new SqlCommand("select * from Employees", conn); conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataSet data = new DataSet(); adapter.Fill(data,"Employees"); data.Tables["Employees"].Columns.Add("Testcolumn"); DataTable t1 = new DataTable("Employees"); DataRow newrow = t1.NewRow(); newrow[0] = "10";\\this the line i am getting error newrow[1] = "Pradeep"; newrow[2] = "Kumar"; data.Tables["Employees"].Rows.Add(newrow); GridView2.DataSource = data; GridView2.DataBind();
请帮帮我谢谢,
您尚未将列添加到DataTable
.
t1.Columns.Add(new DataColumn { DataType = string, ColumnName = "First Name" });
对每个列重复此操作,为每个列提供正确的类型.