|
|
#1 |
|
Addicted Member
Join Date: Nov 05
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
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. |
|
|
|
|
|
#2 | |
|
Fanatic Member
Join Date: Sep 04
Location: Jakarta, Indonesia
Posts: 800
![]() |
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:
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 |
|
Addicted Member
Join Date: Nov 05
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 |
|
Super Moderator
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,107
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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", ).
__________________
Classic VB FAQs (updated Jun 6th) ...Database Development FAQs/Tutorials (updated Mar 26th) (includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial). Tutorial: How to automate Excel from VB6 (or VB5/VBA) .•. SQL 'Select' statement formatter/checker .•. Convert colour number to colour name .•. FlexGrid: fill from recordset .•. FlexGrid: AutoSize columns .•. DB Reserved Words checker Connection strings .•. MDAC/Jet/ACE downloads .•. SQL Server downloads .•. MZTools (free upgrade for the VB6/VBA Editor) |
|
|
|
|
|
#5 |
|
Addicted Member
Join Date: Nov 05
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 13th, 2007 at 12:45 AM. |
|
|
|
|
|
#6 |
|
Super Moderator
Join Date: Jul 02
Location: Bristol, UK
Posts: 27,107
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________
Classic VB FAQs (updated Jun 6th) ...Database Development FAQs/Tutorials (updated Mar 26th) (includes fixing common VB errors) .......... (includes fixing common DB related errors, and [Classic VB] ADO tutorial /further steps, and [VB.Net] ADO.Net Tutorial). Tutorial: How to automate Excel from VB6 (or VB5/VBA) .•. SQL 'Select' statement formatter/checker .•. Convert colour number to colour name .•. FlexGrid: fill from recordset .•. FlexGrid: AutoSize columns .•. DB Reserved Words checker Connection strings .•. MDAC/Jet/ACE downloads .•. SQL Server downloads .•. MZTools (free upgrade for the VB6/VBA Editor) |
|
|
|
|
|
#7 |
|
Addicted Member
Join Date: Nov 05
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. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|