1

In VB.NET we are adding sql parameters without the @ sign and application is working fine:

cmd.Parameters.Add("in_id", SqlDbType.Int).Direction = ParameterDirection.Input

This page says syntax for parameter placeholders depends on the data source and System.Data.SqlClient uses named parameters in the format @parametername.

We are porting the code from Oracle and the same page says for System.Data.OracleClient it uses named parameters in the format :parmname (or parmname), which means the colon is not required.

The page does not explicitly say parameters without @ sign is OK for the Data.SqlClient.

Is the @ sign required before the parameter name (input or output parameter) when using the Data.SqlClient?

Only You
  • 2,051
  • 1
  • 21
  • 34
  • 1
    Sounds like you already answered your question: "...application is working fine." – Nick Vaccaro Feb 22 '13 at 20:45
  • Yes, working fine in our unit test environment. I'm trying to make sure before sending a bunch of code to producion only to find out later on that's a problem. – Only You Feb 22 '13 at 20:49
  • 1
    I think it's an interesting question, since I can't find anywhere in the MSDN documentation where it says that it does officially support it or is recommended to use it that way. Personally I wish it was enforced that all DB providers were required to work that way since it would make them more interchangeable, but it seems like all their examples imply that you should be prefixing the parameter names with the `@`. – Steven Doggart Feb 22 '13 at 20:56
  • @StevenDoggart: Yes, this feature is not documented. However, if you could rely on it would be documented. – Tim Schmelter Feb 22 '13 at 20:58
  • Thank all for the comments and reference to the answer. Read that other question and yes, it is better to manually prefix the parameter name with the @ sign. – Only You Feb 22 '13 at 20:59
  • As a separate topic, it is frustrating not finding that other question/answer using the search box; I tried for like 15 minutes with different sets of keywords. Even the results you get when you decide to type the questioin using same kewords used in your original search is different, even this referenced question did not show up then. Is it only me?? Oh well, yes it might be, I'm Only You after all. – Only You Feb 22 '13 at 21:01
  • 2
    I find Google to be a much more accurate search engine for finding stuff on this site. – Steven Doggart Feb 22 '13 at 21:10
  • OK, good to know. Will use that then. Thanks Seteve. – Only You Feb 22 '13 at 21:21

0 Answers0