To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Database Development

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Apr 11th, 2007, 10:58 PM   #1
barianto
Addicted Member
 
Join Date: Nov 05
Posts: 145
barianto is an unknown quantity at this point (<10)
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 11:10 PM.
barianto is offline   Reply With Quote
Old Apr 12th, 2007, 01:53 AM   #2
erickwidya
Fanatic Member
 
Join Date: Sep 04
Location: Jakarta, Indonesia
Posts: 800
erickwidya will become famous soon enough (50+)
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
Quote:
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
erickwidya is offline   Reply With Quote
Old Apr 12th, 2007, 03:03 AM   #3
barianto
Addicted Member
 
Join Date: Nov 05
Posts: 145
barianto is an unknown quantity at this point (<10)
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)?
barianto is offline   Reply With Quote
Old Apr 12th, 2007, 11:31 AM   #4
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,107
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
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", ).
si_the_geek is offline   Reply With Quote
Old Apr 12th, 2007, 11:28 PM   #5
barianto
Addicted Member
 
Join Date: Nov 05
Posts: 145
barianto is an unknown quantity at this point (<10)
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 13th, 2007 at 12:45 AM.
barianto is offline   Reply With Quote
Old Apr 13th, 2007, 10:07 AM   #6
si_the_geek
Super Moderator
 
si_the_geek's Avatar
 
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,107
si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)si_the_geek has a brilliant future (2000+)
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.
si_the_geek is offline   Reply With Quote
Old Apr 15th, 2007, 03:48 AM   #7
barianto
Addicted Member
 
Join Date: Nov 05
Posts: 145
barianto is an unknown quantity at this point (<10)
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.
barianto is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Database Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:25 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.