locked
Execute SQL - is recordset really necessary ? RRS feed

  • Question

  • Hi

    I'm inserting a row into a table. I was wondering can i just use the connection object directly, or is there some need to use recordset?

    My code:

    -----

    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    With cnn
        .Provider = "MSDASQL"
        .ConnectionString = "DSN=Customer-database;"
        .Mode = adModeShareExclusive
        .Open
    End With

    strSQL = "INSERT INTO customer VALUES ('" & cname & "', '" & cnumber & "')"

    cnn.Execute (strSQL)

    cnn.Close
    Set cnn = Nothing

    -----

    Any suggestions how to make the code better?

    Thanks!

     

    Monday, October 25, 2010 8:08 AM

Answers

  • Since You do an Insert action there is no need for any recordset. If I remember it correct the mode adModeShareExclusive only works with MS Access databases. The DNS connection approach means that the connection string is stored in the Windows registry. Is that bad or good? It's up to You to decide. What we can say is that the solution is not portable and has to be created on each computer that will be using the solution.

     


    Kind regards, Dennis (http://xldennis.wordpress.com/)
    • Marked as answer by Bessie Zhao Monday, November 1, 2010 9:37 AM
    Monday, October 25, 2010 10:50 AM