Results 1 to 4 of 4

Thread: [RESOLVED] ADODB. How to use?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Resolved [RESOLVED] ADODB. How to use?

    Anybody can point it out to me how I'm going to perform multiple query with once conn by using adodb.
    As code been highlighted below has throw me an exception error, "operation is not allow when object is open"
    VB Code:
    1. Try
    2.                 cnn.Open("Provider=SQLOLEDB.1;Password=sa;Persist Security Info=True;User ID=sa;Initial Catalog=Optimizer2;Data Source=LAM")
    3.             Catch exc As Exception
    4.                 DisplayErrorMsg(DatabaseErrorMsg)
    5.             End Try
    6.  
    7.             Dim qry As String = "SELECT PASSWORD FROM S_USER WHERE USER_ID='" & sUserName _
    8.             & "' AND PASSWORD_EXPIRE_DATE > = '" & CurrDate & "'"
    9.             rstRecord.Open(qry, cnn, 3, 3)
    10.  
    11.             If rstRecord.RecordCount = 0 Then
    12.                 'AttemptCount = AttemptCount + 1
    13.                 Dim SelectCountQry As String = "SELECT FAIL_COUNT FROM S_USER WHERE USER_ID='" _
    14.                 & sUserName & "'"
    15.                [B] rstRecord.Open(SelectCountQry, cnn, 3, 3)[/B]
    16.                 Dim nFailCount As Integer = rstRecord.Fields("FAIL_COUNT").Value
    17.                 Dim nNewFailCount As Integer = nFailCount + 1
    18.                 If (nFailCount < 3) Then
    19.                     Dim UpdateCountQry As String = "UPDATE S_USER SET FAIL_COUNT='" & nNewFailCount & _
    20.                     "' WHERE USER_ID ='" & sUserName & "'"
    21.                     Dim AttemptsErrorMsg As String = "You have used" & nNewFailCount _
    22.                     & "out of 3 attempts. The application will been closed if you fail at your last attempt login."
    23.                     DisplayErrorMsg(AttemptsErrorMsg)
    24.                 ElseIf nFailCount = 3 Then
    25.                     Dim LastAttemptsErrorMsg As String = "You have used" & nFailCount _
    26.                     & "out of 3 attempts. Please consult your sdministrator for further information."
    27.                     DisplayErrorMsg(LastAttemptsErrorMsg)
    28.                 End If
    29.                 'DisplayErrorMsg(NotValidUsrMsg)
    Thanks.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ADODB. How to use?

    You've already opened it earlier.

    You should really be using ADO.NET instead since your using VB.NET.

    VB Code:
    1. [b]rstRecord[/b].Open(qry, cnn, 3, 3)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2006
    Posts
    19

    Re: ADODB. How to use?

    I know. I'm newbie of VB.net. this method is recommended by my friend. I know the conn is open, but from the code I posted above, if I want to perform another query as stated as above is
    VB Code:
    1. Dim SelectCountQry As String = "SELECT FAIL_COUNT FROM S_USER WHERE USER_ID='" _
    Am i using the same statement as
    VB Code:
    1. rstRecord.Open(qry, cnn, 3, 3)
    But, my second query string is SelectCountQry instead of qry. So, I need to write as
    VB Code:
    1. qry = "SELECT FAIL_COUNT FROM S_USER WHERE USER_ID='" _
    to perform my second query in the same function.
    I will going trying out ADO.net soon. But, I also need to solve this problem as well. Thanks.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: ADODB. How to use?

    then you need to .Close your recordset object after your done with using the first query. Then .Open it again using the second query.

    Not the pretiest way to do it but it will get the job done.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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