Results 1 to 7 of 7

Thread: passing "Where" value with Prepared Statement?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    passing "Where" value with Prepared Statement?

    Hi, i have this

    Code:
        Set cmdSQLPembayaran = New ADODB.Command
        With cmdSQLPembayaran
            .ActiveConnection = objConnMarketing
            .Prepared = True
            .Parameters.Append .CreateParameter("Periode", adChar, adParamInput, 6)
            .Parameters.Append .CreateParameter("Site", adChar, adParamInput, 1)
            .Parameters.Append .CreateParameter("Slip", adChar, adParamInput, 11)
            .Parameters.Append .CreateParameter("Faktur", adChar, adParamInput, 9)
            .Parameters.Append .CreateParameter("NotaBank", adChar, adParamInput, 9)
            .Parameters.Append .CreateParameter("TanggalSlip", adDate, adParamInput)
            .Parameters.Append .CreateParameter("SudahBayar", adDouble, adParamInput)
            .Parameters.Append .CreateParameter("BayarPokok", adDouble, adParamInput)
            .Parameters.Append .CreateParameter("BayarDenda", adDouble, adParamInput)
            .Parameters.Append .CreateParameter("BayarLebih", adDouble, adParamInput)
            .Parameters.Append .CreateParameter("Slip", adChar, adParamInput, 11)
        End With
    
    
    
        varStrSql = " UPDATE pembayaran SET Periode = ?, Site = ?, Slip = ?, Faktur = ?, NotaBank = ?,  " _
                    & " TanggalSlip = ?, SudahBayar = ?, BayarPokok = ?, BayarDenda = ?, BayarLebih = ? " _
                    & " WHERE Slip = ?"
        With cmdSQLPembayaran
            .CommandType = adCmdText
            .CommandText = varStrSql
        End With
        For x = 1 To (fg.Rows - 1)
                    'cmdSQLPembayaran("Periode") = TAHUN & BULAN
                    'cmdSQLPembayaran("Site") = SITE
                    'cmdSQLPembayaran("NotaBank") = Trim(RemoveChar(myCmbNotaBank.Text, "."))
                    'cmdSQLPembayaran("TanggalSlip") = mytTanggalSetor.Text
                    
                    cmdSQLPembayaran("Slip") = Trim(RemoveChar(fg.TextMatrix(x, 0), ".")) & Trim(fg.TextMatrix(x, 1))
                    cmdSQLPembayaran("Faktur") = Trim(RemoveChar(fg.TextMatrix(x, 0), "."))
                    cmdSQLPembayaran("SudahBayar") = CCur(Trim(fg.TextMatrix(x, 4)))
                    cmdSQLPembayaran("BayarPokok") = CCur(Trim(fg.TextMatrix(x, 6)))
                    cmdSQLPembayaran("BayarDenda") = CCur(Trim(fg.TextMatrix(x, 7)))
                    cmdSQLPembayaran("BayarLebih") = CCur(Trim(fg.TextMatrix(x, 8)))
                    cmdSQLPembayaran.Execute , , adCmdText + adExecuteNoRecords       'Ctatan: the last two arguments used for Execute here makes the execution of the command faster
                    Debug.Print "masuk " & Trim(RemoveChar(fg.TextMatrix(x, 0), ".")) & Trim(fg.TextMatrix(x, 1))
        Next
    I already debug "Slip" Parameter it should meet the condition. But somehow it never meet any condition that it should. What's wrong with my code above?
    Should i create new parameter object for "Slip" since it "calling" twice, once in UPDATE and once in WHERE CLAUSE?
    Should i create different parameter object (adParamOutput, adParamReturnValue, etc) for "Slip" that will use in WHERE Clause?

    Please help....
    Last edited by barianto; Apr 11th, 2007 at 10:10 PM.

  2. #2
    Fanatic Member
    Join Date
    Sep 2004
    Location
    Jakarta, Indonesia
    Posts
    818

    Re: passing "Where" value with Prepared Statement?

    u use adParam output/input/return value if u need to ouput/input/return for Query u specified and is sure need to be SPROC in MSSQL i think..if u need to run it against Access then it must do different way

    u need to pass this Param using @PARAM_NAME and for the query u need to use something like this

    Code:
    SELECT * FROM Table_1 WHERE UserName = @PARAM_NAME
    Should i create new parameter object for "Slip" since it "calling" twice, once in UPDATE and once in WHERE CLAUSE?
    if u the 'Slip' is the same then u don't need to create new param, if not i need to create new param using different name hence make the same in the query

    HTH

    1st NF - a table should not contain repeating groups.
    2nd NF - any fields that do not depend fully on the primary key should be moved to another table.
    3rd NF - there should be no dependency between non key fields in same table.
    - E. Petroutsos -


    eRiCk

    A collection of "Laku-abis" Ebook, Permanent Residence

    Access Reserved Words, a Classic Form Bug, Access Limitation, Know run Process and the Lock they hold in, Logging User Activity in MSSQL,
    Kill Database Processes

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: passing "Where" value with Prepared Statement?

    Thanks Eric,

    But how i passed this @PARAM_NAME using prepared statement?
    Can you give me example (on my code above)?

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: passing "Where" value with Prepared Statement?

    Is the value the same for each (in the Update and Where clauses)?

    If so, simply remove it from the Update clause (and the associated parameter), as it is pointless to update a field to the value it already is.

    If not, change the name of your second Slip parameter (eg: .CreateParameter("SlipOld", ).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: passing "Where" value with Prepared Statement?

    The Value "Slip" Parameter were different (in the UPDATE and WHERE clause).

    If i create different parameter for "Slip" in WHERE clause, how SQL statement will match it with correct field in my table (which is "Slip")?

    Is that parameter regconized by order it declared not by it's name?

    Thanks guys
    Last edited by barianto; Apr 12th, 2007 at 11:45 PM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: passing "Where" value with Prepared Statement?

    The parameters are done by order (the first one you .Append is the first ? in the command text), not by name.

    The name is basically for your own benefit.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: passing "Where" value with Prepared Statement?

    Thanks si_the_geek. Yes it;s by order it append, now i know what solution is best for me.

    Thanks.

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