我有这堂课:
Imports System.Data
Public Class SqlToDataset
#Region "Partial Class DataFields"
#End Region
Public Tables As List(Of DataTable)
Public Structure SqlTable
Dim DataFields As List(Of DataFields)
Dim Rows As List(Of DataRow)
End Structure
Public SqlTables As List(Of SqlTable)
Public Sub New()
Tables = New List(Of DataTable)
SqlTables = New List(Of SqlTable)
End Sub
Public Sub LoadData()
Dim OneSqlTable As New SqlTable
For Each _DataTable As DataTable In Tables
Dim _Fields As New DataFields
For Each _DataColumn As DataColumn In _DataTable.Columns
_Fields.AddField(_DataColumn.ColumnName, _DataColumn.DataType.ToString, _DataTable.Columns.IndexOf(_DataColumn.ColumnName))
Next
OneSqlTable.DataFields.Add(_Fields)
Next
End Sub
End Class
在第OneSqlTable.DataFields.Add(_Fields)
行的子LoadData中,我收到错误,没有设置DataFields。我想,我已经用Dim OneSqlTable As New SqlTable
设置了它。
你能告诉我,我错在哪里吗?
感谢。
答案 0 :(得分:0)
Dim OneSqlTable As New SqlTable
创建一个新的SqlTable对象,但该对象具有null DataFields
属性。
你需要像这样定义SqlTable:
Public Structure SqlTable
Dim DataFields As List(Of DataFields)
Dim Rows As List(Of DataRow)
Public Sub New()
DataFields = New List(Of DataFields)
Rows = New List(Of DataRow)
End Sub
End Structure