Suppose we want to select the data from the database then we write the query for that .
Example:
SqlConnection con=new SqlConnection(Connetion name)
string selectPkId = @"SELECT PK_ID FROM TABLE"
SqlCommand cmd=new SqlCommand(selectPkId ,con);
So,my question is that why we basically use @ before the sql query.If I don’t use @ before that then it again work fine (does not give any error), then what is need of using “@” ? Please tell me.
It’s a verbatim string. This means newlines are preserved and escape sequences ignored:
MSDN Reference: String Literals
This comes in handy when you want escape sequences to be preserved without having to double escape them, eg:
Of course this is a very simple example, but most of the times it will give you a more readable string.