devxlogo

ADO won’t work in VB6

ADO won’t work in VB6

Question:
What is wrong with this picture?

Private Sub cmdIXEDMtest_Click()    Dim con As New ADODB.Connection    Dim rs As New ADODB.Recordset    Dim s As String    Dim constr As String        On Error GoTo FunctionError    constr = "Provider=MSDASQL.1;Persist Security Info=False;User ID=scanctr_user;PWD=please;Data Source=32scanctr"    Set con = New ADODB.Connection    con.Open constr    If (con.State <> adStateOpen) Then        MsgBox "Connection failed!"    End If        Set rs = New ADODB.Recordsets = "SELECT * FROM Batch WHERE System_ID = '008945'"    rs.Open s, cons = rs("Has_DWG")<>        rs.Close    Set rs = Nothing        con.Close    Set con = Nothing    FunctionExit:    Exit SubFunctionError:    Set rs = Nothing    Set con = Nothing    MsgBox "Error: " & Err.Number & " " & Err.Description    Resume FunctionExitEnd Sub

Please offer any suggestions. I have tried different cursor types and specifying client-side cursor location. All to no avail and with the same, useless error message.

Answer:
From what it looks like, you’re not opening an editable Recordset. The rs.Open command needs to be followed (after the two arguments that are already there) by two more constants. The first specifies the cursor type. For an editable recordset, you need to use either adOpenDynamic or adOpenKeyset. The second argument specifies how to lock the recordset. In this case, you’re editing only a single record, so the lock can be an optimistic lock. Use the adLockOptimistic constant. The new line should look like this:

rs.Open s, con, adOpenDynamic, adLockOptimistic

At this point, the edit of the field should work fine.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist