I have this line :
cmd.CommandText = "SELECT registeruser_id,registeruser_username, registeruser_email,registeruser_password FROM TestDB_RegisterUser where registeruser_email='" + email + "' and registeruser_password='" + pwd + "' and registeruser_rowstate<3 ";
And when I try to hit Enter on part of the string , I get a big bunch of red lines that indicates that what I did is considered as error .
How do I break it then ? thanks
Yes, because a regular string literal can't include a line break in the source code. You can include one in a verbatim string literal however:
string sql = @"SELECT FOO
FROM BAR
WHERE X=Y";
Or break it with string concatenation:
string sql = "SELECT FOO " +
"FROM BAR " +
"WHERE X=Y";
More importantly, however, you're currently building your SQL in a horribly insecure way. Never include values directly in the SQL like this. Instead, use parameterized SQL and then specify values for the parameters:
string sql = "SELECT FOO FROM BAR WHERE X=@X";
using (var command = new SqlCommand(sql, connection))
{
command.Parameters.Add("@X", SqlDbType.NVarChar).Value = "...";
using (var reader = command.ExecuteReader())
{
...
}
}
See more on this question at Stackoverflow