By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,514 Members | 1,717 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,514 IT Pros & Developers. It's quick & easy.

Parameter.Add need help - not understanding

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.