Results 1 to 2 of 2

Thread: problem in vb 6.0

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2012
    Posts
    1

    problem in vb 6.0

    Here's My Set of codes, but i've got a problem in my record "rs.open SQL, SETCONNECT, adOpenKeyset, adLockOptimistic"
    But still the same problem. I ve got this error.

    Run-time error '3709'

    the connection cannot be used to perform this operation.
    it is either closed or invalid in this context.


    Please help me reconstruct my codes.


    code
    ------------------------------------------------------------------------


    Private Sub cmdcanacel_Click()
    End
    End Sub

    Private Sub cmdok_Click()
    Dim strsql As String
    Dim rs As ADODB.Recordset
    'OpenConnection
    If txtusername.Text = "" Then
    MsgBox "enter the user name", vbInformation
    txtusername.SetFocus
    Exit Sub

    End If
    If txtpassword.Text = "" Then
    MsgBox "enter the user password", vbInformation
    'txtpassword .SetFocus
    Exit Sub
    End If
    Set rs = New ADODB.Recordset
    strsql = "select loginname,loginpassword from login where loginname='" & txtusername.Text & "'and loginpassword='" & txtpassword.Text & "'"
    rs.Open strsql, g_con, adOpenDynamic, adLockOptimistic (getting error in dis line)
    If rs.EOF = False Then
    welcome.Show
    'MDI.Show
    Else
    MsgBox "Please! enter the username and password correctly", vbCritical
    End If
    rs.Close


    End Sub





    Private Sub Form_Load()
    txtusername.Text = ""
    frmconnection.Hide
    End Sub

    Private Sub txtpassword_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    cmdok_Click
    End If
    End Sub

    Private Sub txtusername_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    cmdok_Click
    End If
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    351

    Re: problem in vb 6.0

    You haven't opened your connection g_con, this needs to be opened before you can open the record set.

    You have a 'Open connection comment but no code to do it.

    See this page for an example:
    http://support.microsoft.com/kb/310985/EN-US
    Rico

    Using: VB.net & MS SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width