我正在尝试使用 vb.net 编写一个 mdb 到 CVS 转换器。我想使用 oledbdata 阅读器获取列标题名称,这是我到目前为止的代码
Public Cheadernames As Array
Public firstRead As Boolean = False
Public columnCount
Dim connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & strfilename
Dim queryString = "SELECT * FROM products"
Dim connection As New OleDbConnection(connectionstring)
Dim command As New OleDbCommand(queryString, connection)
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read
If firstRead Then
columnCount = reader.FieldCount()
firstRead = False
For i = 0 To columnCount - 1
Cheadernames(i) = reader.GetName(i) ' i am getting an error with this line
Console.WriteLine(Cheadernames(i))
Next
End If
所以我试图将所有列标题名称放在一个数组中,但注释行给了我这个错误“对象变量或未设置块变量”