Solved

Equivalent to bind variables

Posted on 2012-03-14
3
329 Views
Last Modified: 2012-08-14
Does the {} syntax denote bind variables ?

_queryString = String.Format("select * from table m " +
                               "WHERE m.col IN " +
                                    "('{0}',  '{1}' )"  +
                                   ,param1, param2);

       Or should I use the typical : operator --> where m.col IN (:param1, :param2);

Thanks!
0
Comment
Question by:Focker513
3 Comments
 
LVL 16

Expert Comment

by:Walter Ritzel
ID: 37722692
In this case, you should use the .NET C# syntax for that, which is the {0} if I remember correctly...
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 150 total points
ID: 37722693
No. Those indicate placeholders for the String.Format method. "{0}" means the first parameter after the format string (in this case: param1). "{1}" means the second parameter (in this case: param2). Each parameter to String.Format after the first parameter (the format string) should correspond to a placeholder within the format string, starting with "{0}" and increasing by 1 for each successive parameter. Placeholders can appear more than once within any given string as well, and each occurrence will be substituted for the value of the associated parameter. See String.Format on MSDN for more information.

As to your bind variable issue, that is handled in this manner:

_queryString = "select * from table m " +
               "WHERE m.col IN " +
               "(:param1,  :param2)";
               
commandObject.Parameters.AddWithValue(":param1", param1);
commandObject.Parameters.AddWithValue(":param2", param2);

Open in new window


The names you choose for the placeholders are arbitrary, but make sure whatever you use in the actual query matches what you put in the AddWithValue call.
0
 

Author Closing Comment

by:Focker513
ID: 37722704
That was my hunch as well.
Thanks for confirming.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question