Solved

Equivalent to bind variables

Posted on 2012-03-14
3
334 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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

738 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