Results 1 to 4 of 4

Thread: [RESOLVED] Ado/sql

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Resolved [RESOLVED] Ado/sql

    Not sure if this would be the right area...But I am wondering if it would be more efficient to use SQL instead of the ADO I am using below.

    Every ADO search I do requires a for loop, and this seems to slow everything down (duh). I am under the impression if I use SQL I won't need one?

    Here is my code..the bolded is the basics of the loop

    VB Code:
    1. Public Sub Supports(Hours As Integer, Payband As String, Account As String)
    2. [b]RsPayband.Open "SupportPayband", cn, adOpenKeyset, adLockPessimistic, adCmdTable
    3.     RsPayband.MoveFirst
    4.     Do While RsPayband.EOF = False[/b]
    5.        'checks to see if Payband matches value in table
    6.        
    7.         If AnniversaryHappened Then
    8.             If (Payband + 1) > MaxPayband Then
    9.                 newpayband = Payband
    10.             Else
    11.                 newpayband = Payband + 1
    12.             End If
    13.            [b] If RsPayband.Fields("payband") = newpayband Then
    14.                 If strLevel <> "0" Then
    15.                     newSupportDailyTotal = ((RsPayband.Fields(strLevel) * (Hours / 5)))
    16.                 End If
    17.             End If[/b]
    18.         End If
    19.             [b]If RsPayband.Fields("Payband") = Val(Payband) Then
    20.                 If strLevel <> "0" Then
    21.                     SupportDailyTotal = ((RsPayband.Fields(strLevel) * (Hours / 5)))
    22.                 End If
    23.             End If
    24.         RsPayband.MoveNext
    25.     Loop
    26.     RsPayband.Close[/b]
    27. End Sub


    I am not sure what the SQL would look like, but I am guessing something like this

    VB Code:
    1. RsPayband.Open "Select * from SupportPayband", cn, adOpenKeyset, adLockPessimistic
    2.  
    3. SupportDailyTotal = "Select " + txtlevel.text + " from SupportPayband where Payband = " + txtPayband.text

    Or something along those lines (I've never used SQL )

    Anyways, any tips would be appreciated

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Ado/sql

    Using SQL to get a single record is the better way to do it.

    More like:

    Code:
    Dim strSQL as String
    
    strSQL = "Select " + txtlevel.text + " from SupportPayband where Payband = " + txtPayband.text
    
    Debug.Print strSQL ' Just so you can see the query you are about to execute!
    
    RsPayband.Open strSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Ado/sql

    hrm, it keeps giving me a type mismatch error

    debug is printing


    "Select Level3 from SupportPayband where Payband = 2"

    Which looks right to me

    would that kind of select work for a table with the following layout?

    Code:
    Payband     Level1     Level2     Level3      Level4     Level5
       1         ##.##      ##.##      ##.##      ##.##     ##.##
       2         ##.##      ##.##      ##.##      ##.##     ##.##
       3         ##.##      ##.##      ##.##      ##.##     ##.##
       4         ##.##      ##.##      ##.##      ##.##     ##.##
    ?


    also, how would I display the information I have pulled out?
    Last edited by kfcSmitty; Jul 19th, 2005 at 09:50 AM.

  4. #4

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Ado/sql

    Okay, figured out the type mismatch error. Now I need to know how to display the information I have pulled out

    *edit* Figured the rest out, thanks
    Last edited by kfcSmitty; Jul 19th, 2005 at 10:22 AM.

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