load excel into dataset from asp.net page

G

Guest

Hi there,
I load an excel file from an asp.net page and try to read it into a dataset.
The problem is that it tells me: Database or object is read-only
It only needs to be read only. Here is the code. Could someone please advice
me what I am doing wrong. Thank you Chris
(FileExcel is the input field)

System.IO.Stream sio;
sio = FileExcel.PostedFile.InputStream;
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data
Source=" + sio + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]",
objConn);
OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
objAdapter1.SelectCommand = objCmdSelect;
DataSet dsExcel = new DataSet();
objAdapter1.Fill(dsExcel);
objConn.Close();
 
C

Cor Ligthert

Chris,

Why you use that SIO, in the connection you have just to set the path to the
excel file.

I hope this helps,

Cor
 

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