Excel Import with VB.NET

qtip07

New member
Joined
Feb 7, 2007
Messages
1
Programming Experience
Beginner
The code below has been working for a couple months. Recently a user tried to upload a file, but it is returning this error.

There is no row at position 0.

There is a sheet in the .xls called Sheet1 in the 0 postion. Any ides why it can't find it? Thanks!
VB.NET:
Try
    Dim dttables As New DataTable
    Dim xlcn As OleDbConnection
    Dim i As Integer
    xlcn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
      Server.MapPath("uploads/") & strFileNameOnly & ";Extended Properties=Excel 8.0")
    xlcn.Open()
    dttables = xlcn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
    Dim strTemp(dttables.Rows.Count) As String
    For i = 0 To 0
        strTemp(i) = dttables.Rows(i)(2)
        cSheet = strTemp(i)
    Next
    dttables.Dispose()
    xlcn.Close()
    xlcn.Dispose()
Catch ex As Exception
    Response.Redirect("default.aspx?msg=" & ex.Message)
End Try
 
Last edited by a moderator:
Back
Top