Help with importing excel files

Discussion in '.NET' started by pmb88, Feb 26, 2012.

  1. pmb88


    Jan 25, 2011
    Likes Received:
    I am creating a web application that imports excel files into a database. What occurs is that i have several excel files that I need to import from excel into a database. These files could be excel 97-2003 or excel 2007/2010. I have it determine which filetype it is and use the particular connection. This is how my code looks.
    Code (Text):

    Dim strconn As String
           If fileextesnison = ".xlsx" Then
                strconn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath +
      ";Extended Properties=""Excel 12.0 Xml;"";"
                strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath+
    ";Extended Properties=""Excel 8.0;"";"
          End if
    Dim strSQL as string = "SELECT * FROM RangeName"
    Dim olConn As New OleDbConnection(strconn)
    Dim oadapter As OleDbDataAdapter
    Dim od As New OleDbCommand(strSQL, olConn)
        oadapter.selectcommand = od
    Dim oData as dataset
           oadapter.fill(odata, "Data")
    Before the above process happens I am using softartisan excel writer to add a range name cause I am using the range name to select the data and adding [ and ] in the column names in case the column names are not valid database column name format. The issue is that when I try to import the file that is excel 97-2003 it gives me the microsoft jet database engine could not find 'RangeName' and please make sure that the path and filename is correct. When I try this with excel 2007/2010 it imports the file and have no issues. I have checked the filepath and it is directing to the proper file. What could be the issue that is occurring here?
    Last edited: Feb 26, 2012
    pmb88, Feb 26, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.