Solved

Equivalent to bind variables

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

919 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now