0
vb.net을 사용하여 CVS 변환기에 mdb를 쓰려고합니다. 내가 열이 여기에 oledbdata 판독기를 사용하여 이름을 헤더하고 싶어 지금까지 너무vb.net 개체 변수 또는 With 블록 변수가 설정되지 않았습니다. OleDbDataReader
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
내가 배열에있는 모든 열 머리글 이름을 넣어 노력하고 있지만, 주석 라인은 저에게이 오류가 있습니다 "개체 내 코드입니다 변수 또는 With 블록 변수가 설정되지 않음 "
문제는 Cheadernames 반환 배열이 초기화되지 않는다는 것입니다. 먼저 반환 배열 (초기화해야 함)을 사용한 다음 해당 배열을 반환해야합니다. http://www.dotnetperls.com/array-vbnet 및 반환 배열 섹션을 살펴보십시오. –