+ Reply to Thread
Results 1 to 2 of 2

Import csv file into excel programmatically

  1. #1
    Saumin
    Guest

    Import csv file into excel programmatically

    hi,
    I want to import a csv file into my excel template file programmatically in
    a windows application. i am using vb.net, ado.net to do this. but i am
    getting an error: Operation must use an updateable query. I have checked
    security and it is fine. aspnet user has full permissions on both the files.
    I will really appreciate a quick response. following is the code:
    csvPath = "c:\"
    strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""", csvPath)

    Dim objCSVConn As New OleDbConnection(strCSVConn)
    objCSVConn.Open()
    Dim objCmd As New OleDbCommand
    objCmd.Connection = objCSVConn
    Try
    objCmd.CommandText = "Insert INTO [Sheet1$] IN 'C:\Book1.xls'
    'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
    objCmd.ExecuteNonQuery()
    objCSVConn.Close()
    Catch ex As Exception
    If Not (objCSVConn Is Nothing) Then
    objCSVConn.Close()
    End If
    MsgBox(ex.Message)
    End Try

    Thanks,
    Saumin


  2. #2
    Jamie Collins
    Guest

    Re: Import csv file into excel programmatically


    Saumin wrote:
    > hi,
    > I want to import a csv file into my excel template file

    programmatically in
    > a windows application. i am using vb.net, ado.net to do this. but i

    am
    > getting an error: Operation must use an updateable query. I have

    checked
    > security and it is fine. aspnet user has full permissions on both the

    files.
    > I will really appreciate a quick response. following is the code:
    > csvPath = "c:\"
    > strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""",

    csvPath)
    >
    > Dim objCSVConn As New OleDbConnection(strCSVConn)
    > objCSVConn.Open()
    > Dim objCmd As New OleDbCommand
    > objCmd.Connection = objCSVConn
    > Try
    > objCmd.CommandText = "Insert INTO [Sheet1$] IN

    'C:\Book1.xls'
    > 'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
    > objCmd.ExecuteNonQuery()
    > objCSVConn.Close()
    > Catch ex As Exception
    > If Not (objCSVConn Is Nothing) Then
    > objCSVConn.Close()
    > End If
    > MsgBox(ex.Message)
    > End Try
    >
    > Thanks,
    > Saumin



    Saumin wrote:
    > hi,
    > I want to import a csv file into my excel template file

    programmatically in
    > a windows application. i am using vb.net, ado.net to do this. but i

    am
    > getting an error: Operation must use an updateable query. I have

    checked
    > security and it is fine. aspnet user has full permissions on both the

    files.
    > I will really appreciate a quick response. following is the code:
    > csvPath = "c:\"
    > strCSVConn = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source={0};Extended Properties=""text;HDR=No;FMT=Delimited""",

    csvPath)
    >
    > Dim objCSVConn As New OleDbConnection(strCSVConn)
    > objCSVConn.Open()
    > Dim objCmd As New OleDbCommand
    > objCmd.Connection = objCSVConn
    > Try
    > objCmd.CommandText = "Insert INTO [Sheet1$] IN

    'C:\Book1.xls'
    > 'Excel 8.0;' SELECT * FROM 261_WildOats_12292004_EE.csv"
    > objCmd.ExecuteNonQuery()
    > objCSVConn.Close()
    > Catch ex As Exception
    > If Not (objCSVConn Is Nothing) Then
    > objCSVConn.Close()
    > End If
    > MsgBox(ex.Message)
    > End Try
    >


    When using Text in the extended properties, the provider does not seem
    to support the IN <database> syntax. Try doing the other way round i.e.
    use Excel 8.0 in the ADO connection string and Text in the IN clause.
    Jamie.

    --


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1