Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 781839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:17:38+00:00 2026-05-14T20:17:38+00:00

i am trying to add data to mysql from excel. i am getting the

  • 0

i am trying to add data to mysql from excel. i am getting the above error on this line: rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic

here is my code:

Dim oConn As ADODB.Connection

Private Sub ConnectDB()
    Set oConn = New ADODB.Connection
    oConn.Open "DRIVER={MySQL ODBC 5.1 Driver};" & _
        "SERVER=localhost;" & _
        "DATABASE=employees;" & _
        "USER=root;" & _
        "PASSWORD=some_pass;" & _
        "Option=3"

End Sub

Function esc(txt As String)
    esc = Trim(Replace(txt, "'", "\'"))
End Function


Private Sub InsertData()
Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    ConnectDB
    With wsBooks
        For rowCursor = 2 To 11
            strSQL = "INSERT INTO tutorial (author, title, price) " & _
                "VALUES ('" & esc(.Cells(rowCursor, 1)) & "', " & _
                "'" & esc(.Cells(rowCursor, 2)) & "', " & _
                esc(.Cells(rowCursor, 3)) & ")"
            rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic
        Next
    End With
End Sub

whats wrong with rs.Open strSQL, oConn, adOpenDynamic, adLockOptimistic ?
why am i getting the odbc error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:17:38+00:00Added an answer on May 14, 2026 at 8:17 pm

    INSERT does not return a recordset. Use oConn.Execute to do this kind of insert.

    Another option might be the this particular version of mysql driver does not support adOpenDynamic (are you sure you need it?) or adLockOptimistic (same).

    But anyway, this code is an sql injection hole. You should consider using parametrised queries:

    dim cm as adodb.command
    set cm=new adodb.command
    set cm.activeconnection = oConn
    cm.commandtype = adcmdtext
    cm.commandtext = "insert tutorial (author, title, price) values (?,?,?)"
    cm.parameters.add cm.createparameter(,adVarChar,adParamInput,50,esc(.Cells(rowCursor, 1)))
    cm.parameters.add cm.createparameter(,adVarChar,adParamInput,50,esc(.Cells(rowCursor, 2)))
    cm.parameters.add cm.createparameter(,adDouble,adParamInput,,esc(.Cells(rowCursor, 3)))
    
    cm.execute ,, adExecuteNoRecords
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.