Simple question

  • Thread starter Thread starter Phil Hunt
  • Start date Start date
P

Phil Hunt

What is the significance of and @ prefix of a string. I see it mostly used
in a SQL statement .

Thanks
 
"@" has no general significance in a string.

In SQL statements, some data providers use "@" to indicate a
parameter. Using parameters rather than putting the values directly
in the SQL statement has several advantages, including automatic data
type conversion, prevention of SQL injection attacks and the ability
for the backend to calculate the execution plan once for multiple uses
of the statement.
 
I understand what you are saying.
But maybe I should give an example right out of a book I am reading.

In C# :
String strConn = @"Data Source=.\SQLExpress;" +
"Initial Catalog=Northwind"

The @ sign is not insdei the string. I cannot find any explanation anywhere
what this means.

TIA
 
Now I think about it. It may something to do with the escaple character \

Right ?
 
Hi Phil,

That is because if you dont use @, you have to use \\ to express \ inside
a string..

So, if you dont use @,
String strConn = "Data Source=.\\SQLExpress;Initial Catalog=Northwind"

and if you use @,
String strConn = @"Data Source=.\SQLExpress;Initial Catalog=Northwind"

Look at MSDN for more information,

Jigar Mehta
 
Phil Hunt said:
I understand what you are saying.
But maybe I should give an example right out of a book I am reading.

In C# :
String strConn = @"Data Source=.\SQLExpress;" +
"Initial Catalog=Northwind"

The @ sign is not insdei the string. I cannot find any explanation anywhere
what this means.

It's a verbatim string literal:

http://pobox.com/~skeet/csharp/strings.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top