如何在vb.net中阅读和查看Excel文件 [英] How to read and view Excel file in vb.net
问题描述
If (Radiobuttonlist1.SelectedItem.Value = 2) Then
Dim path As String
'path = upload.PostedFile.FileName
path = "D:\Karthi Scripts\XML CHK\shg_repayment.xls"
'Response.Write(path)
'Response.End()
Dim connect As String
connect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= '" + path + "'" + "Extended Properties='Excel 4.0;HDR=Yes;IMEX=1;'"
Dim conn As New OleDbConnection(connect)
conn.Open()
Dim ds = New DataSet()
Dim od As New OleDbCommand("SELECT * FROM [Sheet1$]", conn)
Dim orr As OleDbDataReader
grdView.DataSource = orr
grdView.DataBind()
conn.Close()
End If
上面的代码我用来读取Excel文件并在Gridview中查看.但出现以下错误
初始化字符串的格式不符合OLE DB规范.
The above code I have used to read the excel file and view in the Gridview. But I am getting the following error
Format of the initialization string does not conform to the OLE DB specification.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Format of the initialization string does not conform to the OLE DB specification.
Source Error:
Line 341: connect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= '" + path + "'" + "Extended Properties='Excel 4.0;HDR=Yes;IMEX=1;'"
Line 342: Dim conn As New OleDbConnection(connect)
Line 343: conn.Open()
Line 344: Dim ds = New DataSet()
Line 345: Dim od As New OleDbCommand("SELECT * FROM [Sheet1$]", conn)
为此发布解决方案.
在此先感谢
Post solution for this.
Thanks in advance
推荐答案
",conn) Dim orr As OleDbDataReader grdView.DataSource = ORR grdView.DataBind() conn.Close() 结束 如果
", conn) Dim orr As OleDbDataReader grdView.DataSource = orr grdView.DataBind() conn.Close() End If
上面的代码我用来读取Excel文件并在Gridview中查看.但出现以下错误
初始化字符串的格式不符合OLE DB规范.
The above code I have used to read the excel file and view in the Gridview. But I am getting the following error
Format of the initialization string does not conform to the OLE DB specification.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Format of the initialization string does not conform to the OLE DB specification.
Source Error:
Line 341: connect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= '" + path + "'" + "Extended Properties='Excel 4.0;HDR=Yes;IMEX=1;'"
Line 342: Dim conn As New OleDbConnection(connect)
Line 343: conn.Open()
Line 344: Dim ds = New DataSet()
Line 345: Dim od As New OleDbCommand("SELECT * FROM [Sheet1
" ,conn)
", conn)
为此发布解决方案.
预先感谢
Post solution for this.
Thanks in advance
您好,
有一个失踪者;在您的连接字符串中.
Hello,
There is a missing ; in your connection string.
connect = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= ''" + path + "''" + ";Extended Properties=''Excel 4.0;HDR=Yes;IMEX=1;''"
在这里看看:
http://www.connectionstrings.com/excel [
Have a look here:
http://www.connectionstrings.com/excel[^]
Valery.
这篇关于如何在vb.net中阅读和查看Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!