Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: NT
Expertise: Beginner
May 2, 1999

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.Recordset

s = "SELECT * FROM Batch WHERE System_ID = '008945'"
    rs.Open s, con

s = rs("Has_DWG")

<>

    
    rs.Close
    Set rs = Nothing
    
    con.Close
    Set con = Nothing
    
FunctionExit:
    Exit Sub
FunctionError:
    Set rs = Nothing
    Set con = Nothing
    MsgBox "Error: " & Err.Number & " " & Err.Description
    Resume FunctionExit
End 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.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap