I am trying to read a string that includes a backslash in it from a sql table. For some reason I can not pass the back slash within the string.
My string is the user name and its in this format: Domain\username
I send it to the table as so:
SqlCommand scomm = new SqlCommand();
SqlDataReader sr;
string nameOfUser = "Domain\userName";
scomm.CommandText = "SELECT * FROM tableOfUsers WHERE UserName=" + nameOfUser;
sr = scomm.ExecuteReader();
During the debug I can see that another backslash is added as an escape character however I don’t know what happens with the sql part and why an exception is thrown. I tried using @ but that didn’t help either.
I would appreciate any help you can provide me.
Use
SqlParameter.