Solved

Equivalent to bind variables

Posted on 2012-03-14
3
326 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
Comment Utility
In this case, you should use the .NET C# syntax for that, which is the {0} if I remember correctly...
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 150 total points
Comment Utility
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
Comment Utility
That was my hunch as well.
Thanks for confirming.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
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.

744 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

12 Experts available now in Live!

Get 1:1 Help Now