Query and Display Excel

G

Guest

Hello there

I am using the following code to query data from Excel shee

try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +"DataSource=C:\\Temp\\MSFT.xls" +"Extended Properties=Excel 8.0;";
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);

DataSet myDataSet = new DataSet();

myCommand.Fill(myDataSet, "ExcelInfo");
}
catch(Exception E)
{
Console.WriteLine(E.Message);
}

But got the following error message"Could not find installable ISAM."
Anybody knows about what I did wrong

Thanks muc
Qin Zhou
 
M

Miha Markic [MVP C#]

Hi,

You connection string is wrong.
It should be:
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=C:\\Temp\\MSFT.xls;" +
"Extended Properties=\"Excel 8.0;HDR=Yes;\"";

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Q.Z. said:
Hello there,

I am using the following code to query data from Excel sheet

try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
+"DataSource=C:\\Temp\\MSFT.xls" +"Extended Properties=Excel 8.0;";
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);

DataSet myDataSet = new DataSet();

myCommand.Fill(myDataSet, "ExcelInfo");
}
catch(Exception E)
{
Console.WriteLine(E.Message);
}

But got the following error message"Could not find installable ISAM."
Anybody knows about what I did wrong?

Thanks much
Qin Zhou
 
K

Kevin Yu [MSFT]

Thanks for Miha's quick response.

Hi Qin,

Thank you for posting in the community!

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that an exception which says "Could not find
installable ISAM." was thrown when you're filling the dataset.

As Miha said, there is something wrong with your connection string. There
has to be a space between Data and Source. And we have to add a semicolon
';' after the source file name.

You can also obtain a connection string by creating an .udl file. To create
a .udl file, try the following steps:
1. Create a text file on the desktop and rename it to .udl. (For example
a.udl. Make sure you have shown full name with extension.)
2. Double click to open a Data Link Properties dialog box. You can
connection to the data source file using wizards.
3. Open the .udl file in the Notepad. You will see the connection string in
the file.

For more information about OleDb connection strings, please check the
following link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdataoledboledbconnectionclassconnectionstringtopic.asp

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top