Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
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

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.

VB
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
Posted
Updated 14-Dec-11 0:27am
v2

1 solution

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;'"


Have a look here:

http://www.connectionstrings.com/excel[^]

Valery.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900