469,579 Members | 1,830 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Parameter.Add need help - not understanding

Hello,
I'm somewhat new to DB programming and have a question. I am now taking
over an application that a previous programmer had written and he had
made use of the Parameter.Add function for DB2 comman objects. This is
what is trying to be done:

An sql statement is created that uses ? as value markers. This value is
passed into a function that calls the Parameter.Add function. What is
supposed to happen is that the first ? is replaced with the value
passed to the function. What is happening is that ALL of the ? markers
are replaced, not just the first one. Here is an example sql statement
and function call:
*note I am using vb.net*

SELECT test_one, test_two
FROM mydb.test_param
WHERE test_three = ?
AND test_four = ?

db.AddParameter(tstParam) // this is the function call
CType(Cmnd,DB2Command).Parameters.Add("aParam",tst Param)) // this is
the db2 function call.

Ok now if the AddParameter call is made once before executing the sql
statement it appears to work fine. But if there is more than one call
of AddParameter before the sql statement is executed then there is an
error. What happens is that when the Parameters.Add db2 function is
called it is replacing both ? markers instead of just the first one.
Does anyone have a suggestion on how to make it replace only the first
one or a better way of doing this function?

Thanks in advance for any and all help.

Apr 3 '06 #1
1 1848
Vaelek wrote:
Hello,
I'm somewhat new to DB programming and have a question. I am now taking
over an application that a previous programmer had written and he had
made use of the Parameter.Add function for DB2 comman objects. This is
what is trying to be done:

An sql statement is created that uses ? as value markers. This value is
passed into a function that calls the Parameter.Add function. What is
supposed to happen is that the first ? is replaced with the value
passed to the function. What is happening is that ALL of the ? markers
are replaced, not just the first one. Here is an example sql statement
and function call:
*note I am using vb.net*

SELECT test_one, test_two
FROM mydb.test_param
WHERE test_three = ?
AND test_four = ?

db.AddParameter(tstParam) // this is the function call
CType(Cmnd,DB2Command).Parameters.Add("aParam",tst Param)) // this is
the db2 function call.

Ok now if the AddParameter call is made once before executing the sql
statement it appears to work fine. But if there is more than one call
of AddParameter before the sql statement is executed then there is an
error. What happens is that when the Parameters.Add db2 function is
called it is replacing both ? markers instead of just the first one.
Does anyone have a suggestion on how to make it replace only the first
one or a better way of doing this function?


It would be good to know the programming language you are using.

As for the problem, you should use an additional parameter for the
AddParameter routine so that the routine knows which parameter marker the
provided value is for. Or you use some implicit counting inside the
function...

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Brandolon Hill | last post: by
16 posts views Thread by hzmonte | last post: by
8 posts views Thread by =?Utf-8?B?UmF2aQ==?= | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.