THIS IS MY CODE
Private Sub GetDataFromXLS()
Dim strConn As String
Dim objConn As OleDbConnection
Dim sql As String
strConn = _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Data.xls;" & _
"Extended Properties=Excel 8.0;HDR=Yes;"
objConn = New OleDbConnection(strConn)
objConn.Open()
sql = "SELECT ProductCode, ProductName FROM [Data$]"
'-Data is name of sheet in Data.xls.
Dim objCommand As New OleDbCommand(sql, objConn)
Dim objAdapter As New OleDbDataAdapter(objCommand)
Dim objDS As New DataSet
objAdapter.Fill(objDS)
With Me.gridProduct
.DataSource = objDS.Tables(0).DefaultView
.DataBind()
End With
objConn.Close()
End Sub
I use Excel 2003.
I don't understand where's wrong in above, but it showed error following:
Line 50: strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data.xls;Extended Properties=Excel 8.0;HDR=Yes;"
Line 51: objConn = New OleDbConnection(strConn)
Line 52: objConn.Open()
Line 53:
Line 54: sql = "SELECT ProductCode, ProductName FROM [Data$]"
[OleDbException (0x80004005): Unspecified error]
System.Data.OleDb.OleDbConnectionInternal.Initiali zeProvider() +135
System.Data.OleDb.OleDbConnectionInternal..ctor(Ol eDbConnection conn, OleDbConnectionString constr) +84
System.Data.OleDb.OleDbConnectionFactory.CreateCon nection(DbConnectionOptions options, Object providerInfo, DbConnectionBase owningObject) +55
System.Data.ProviderBase.DbConnectionFactory.Creat eNonPooledConnection(DbConnectionBase owningConnection, DbConnectionPoolGroup poolGroup) +26
System.Data.ProviderBase.DbConnectionFactory.GetCo nnection(DbConnectionBase owningConnection) +51
System.Data.ProviderBase.DbConnectionClosed.Open(D bConnectionBase outerConnection) +189
System.Data.ProviderBase.DbConnectionBase.Open() +62
GUIVP.ImportData.btnView_Click(Object sender, EventArgs e) in E:\Inetpub\wwwroot\GUIVP\Admin\ImportData.aspx.
vb: 52
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +232
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +5
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +31
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5157
Please help me in this situation.
Thank you alot.
L.V.L