Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT Statement against Excel file?

Status
Not open for further replies.

ashishraj14

Programmer
Mar 1, 2005
92
AU
How can I run sql statement against excel file. I am using office 2003 and want to run retrieve information from a column in excel file.

SELECT DISTINCT Code FROM Excel_File_name? Is this possible?

Thanks
 
sort of.

you can use an odbc or oledb link and then run a select against it.

Goto for the correct connectionstring to connect to the excell file.



Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
hi chrissie1

i am getting an error saying "Could not find installable ISAM". What this could be?

thanks
 
ThatRickGuy,

that didn't help, still comes up with the error. this is what i am doing

Dim conn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source='" & "C:\Temp\SSPortfolio.xls" & " '; " & _
"Extended Properties=Excel 8.0;" & "HDR=Yes;" & "IMEX=1")


'! Select the data from Sheet1 of the workbook.
Dim da As New OleDbDataAdapter("SELECT * FROM [SSPortfolio$]", conn)

Dim ds As New DataSet

da.Fill(ds)

DataGridView1.DataSource = ds.Tables(0)

does "Extended Properties=Excel 8.0" in the connection refers to interop library 8.0??? i have office 2003 installed, which uses interop library 11.0, cud that be a cause of error???
 
The problem is with Extended Property in Connection string... but you get "installable ISAM" error... it’s weird…

when u google this error u'll get lots of doc, but none of them will say first check connection string

actually Extended Property needs string with double quotes inside the connection string.
Simply do this

Dim strFilePath As String = "C:\Temp\SSPortfolio.xls"

Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFilePath & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""")
 
This is what works for me.

Dim Con as ADODB.Connection
Con = New ADODB.Connection
Con.ConnectionString="Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=C:\Temp\SSPortfolio.xls;DefaultDir=C:\Temp;"


SQLString="SELECT * FROM [SSPortfolio$]" (I'm assuming that SSPortfolio$ is the name of your worksheet.)

I've never tried this with an OLEDBAdapter, however.

I hope this helps.

Ron

Ron Repp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top