ASP.NET Reading problem (reading .xls)

  • Thread starter Thread starter Wael Soliman
  • Start date Start date
W

Wael Soliman

hi all
when i try to read from .xls file in .NET windows application
it work correctly but when i try to use the same connection string in
the asp.net i fail while the connection is the same
i need the right connection string and the rigth way to read .xls file
from asp.net

using ADO.NET in both

best regards
 
Try this using the OLEDBonnection object

Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=FULLYQUALIFIEDPATHANDFILENAMEHERE;Extended Properties=Excel 8.0;
 
Try this ..

Dim sbConn As StringBuilder = New StringBuilder
sbConn.Append("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
filePath)
sbConn.Append(";Extended Properties=")
sbConn.Append(Convert.ToChar(34))
sbConn.Append("Excel 8.0;HDR=Yes;IMEX=2")
sbConn.Append(Convert.ToChar(34))


Dim cnExcel As OleDbConnection = New
OleDbConnection(sbConn.ToString())
cnExcel.Open()
Dim cmdExcel As OleDbCommand = New OleDbCommand("select * from
[sheet1$]", cnExcel)

Dim drExcel As OleDbDataReader
Try
drExcel =
cmdExcel.ExecuteReader(CommandBehavior.CloseConnection)


cmdExcel.Dispose()
If cnExcel.State = ConnectionState.Open Then
cnExcel.Close()
End If
cnExcel.Dispose()
 
Back
Top