vb.net 如何将DataRow添加到DataTable里
我有一段语句:DimdtAsDataRow()dt=ReturnGoods_Search_DataSet.Tables("ZT_Transfers").Select(Sq...
我有一段语句:
Dim dt As DataRow()
dt = ReturnGoods_Search_DataSet.Tables("ZT_Transfers").Select(SqlStrng)
Dim dataTabl1 As DataTable = New DataTable
如何将dt添加到dataTabl1里去? 展开
Dim dt As DataRow()
dt = ReturnGoods_Search_DataSet.Tables("ZT_Transfers").Select(SqlStrng)
Dim dataTabl1 As DataTable = New DataTable
如何将dt添加到dataTabl1里去? 展开
2个回答
展开全部
声明
Public Class DataRow
用法
Dim instance As DataRow
示例通过调用 DataTable 对象的 NewRow 方法创建新的 DataRow。
Private Sub CreateNewDataRow()
' Use the MakeTable function below to create a new table.
Dim table As DataTable
table = MakeNamesTable()
' Once a table has been created, use the
' NewRow to create a DataRow.
Dim row As DataRow
row = table.NewRow()
' Then add the new row to the collection.
row("fName") = "John"
row("lName") = "Smith"
table.Rows.Add(row)
Dim column As DataColumn
For Each column in table.Columns
Console.WriteLine(column.ColumnName)
Next
DataGrid1.DataSource=table
End Sub
Private Function MakeNamesTable() As DataTable
' Create a new DataTable titled 'Names.'
Dim namesTable As DataTable = new DataTable("Names")
' Add three column objects to the table.
Dim idColumn As DataColumn = new DataColumn()
idColumn.DataType = System.Type.GetType("System.Int32")
idColumn.ColumnName = "id"
idColumn.AutoIncrement = True
namesTable.Columns.Add(idColumn)
Dim fNameColumn As DataColumn = New DataColumn()
fNameColumn.DataType = System.Type.GetType("System.String")
fNameColumn.ColumnName = "Fname"
fNameColumn.DefaultValue = "Fname"
namesTable.Columns.Add(fNameColumn)
Dim lNameColumn As DataColumn = new DataColumn()
lNameColumn.DataType = System.Type.GetType("System.String")
lNameColumn.ColumnName = "LName"
namesTable.Columns.Add(lNameColumn)
' Create an array for DataColumn objects.
Dim keys(0) As DataColumn
keys(0) = idColumn
namesTable.PrimaryKey = keys
' Return the new DataTable.
MakeNamesTable = namesTable
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询