Solved

Equivalent to bind variables

Posted on 2012-03-14
3
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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.

689 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