问题描述
嗨伙计们,
我需要帮助,了解为什么我的Excelconnection字符串会出现此错误的原因,当我设置HDR =是时,我一直遇到d错误但是HDR =否,它返回F1,F2,......:
错误:对象引用未设置为实例一个物体?
hi guys,
I need help in understanding what could possibly be the reason why am getting this error with my Excelconnection string, when i set HDR=Yes, i keep encountering d error below but with HDR=No, it return F1, F2, ......:
Error: Object reference not set to an instance of an object?
Dim XConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & UZO.FileName & ";" & " Extended Properties=Excel 8.0;Imex=2;HDR=Yes")
请帮忙,因为我需要它返回第1行作为标题/列而不是F1,F2 .....
Thanx家伙事先
Kindly help out coz i need it to return d 1st row as the headers/column and not F1, F2 .....
Thanx guys in advance
推荐答案
Dim xConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & UZO.FileName & ";Extended Properties=""Excel 8.0;Imex=2;HDR=Yes""")
<pre lang="vb">Private _blnMixedData As Boolean = True
Private _blnHeaders As Boolean = True</pre>
Private Function ExcelConnection() As String
Return "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & SVTest & ";" & "Extended Properties=" & Convert.ToChar(34).ToString() & "Excel 8.0;" & "HDR=YES;" & "Imex=2;" & Convert.ToChar(34).ToString()
End Function
Private Function ExcelConnection() As String
Return "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & SVTest & ";" & "Extended Properties=" & Convert.ToChar(34).ToString() & "Excel 8.0;" & ExcelConnectionOptions() & Convert.ToChar(34).ToString()
End Function
Private Function ExcelConnectionOptions() As String
Dim strOpts As String = ""
If Me.MixedData = True Then
strOpts += "Imex=2;"
End If
If Me.Headers = True Then
strOpts += "HDR=Yes;"
Else
strOpts += "HDR=No;"
End If
Return strOpts
End Function
Private Sub RetrieveSheetnames()
Try
Me.ComboBox1.Items.Clear()
If _exr IsNot Nothing Then
_exr.Dispose()
_exr = Nothing
End If
_exr = New ExcelReader()
_exr.ExcelFilename = ExcelFilename
_exr.Headers = True
_exr.MixedData = True
Dim sheetnames As String() = Me._exr.GetExcelSheetNames()
Me.ComboBox1.Items.AddRange(sheetnames)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub
非常感谢您的帮助。
非常感谢
Your kind assistance would be highly appreciated.
Thanks alot
这篇关于Excel连接字符串出错(HDR =是)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!