送分问题,快来抢答!!!
如何新建一个datatable如:
姓名
张三
李四
王五
的列名为"姓名",数据三条的dt,请写出具体代码
[解决办法]
DataTable dt=new DataTable();
dt.columns.add("name");
dt.columns.add("columnname");
dt.rows.add(new object[]{"张三","aaaa"});dt.rows.add(new object[]{"张三","aaaa"});
[解决办法]
Dim dt As New DataTable() Dim dcname As DataColumn = New DataColumn("name", GetType(System.String), Nothing, System.Data.MappingType.Attribute)dt.Columns.Add(dcname)dt.rows.add(New Object() {"张三"}) dt.rows.add(New Object() {"李四"}) dt.rows.add(New Object() {"王五"})
[解决办法]
Dim dt As New DataTable
dt.Columns.Add("姓名")
dt.Rows(0)("姓名") = "张三"
dt.Rows(1)("姓名") = "李四"
dt.Rows(2)("姓名") = "王五"
[解决办法]
Dim dt As New DataTable dt.Columns.Add("姓名") Dim dataRow As DataRow dataRow = dt.NewRow() dt.Rows.Add(dataRow) dataRow = dt.NewRow() dt.Rows.Add(dataRow) dataRow = dt.NewRow() dt.Rows.Add(dataRow) dt.Rows(0)("姓名") = "张三" dt.Rows(1)("姓名") = "李四" dt.Rows(2)("姓名") = "王五"
[解决办法]
8楼正解,5楼应该有问题吧?