SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string cmdstr = "select count(*) from [Registration] where UserName'" + txtUsername.Text + "' ";
SqlCommand cmd = new SqlCommand(cmdstr, con);
int temp = Convert.ToInt32(cmd.ExecuteScalar().ToString()); //its giving error on this line.
con.Close();
I am getting this exception :
System.Data.SqlClient.SqlException: Incorrect syntax near 'Deepali'.
when i enter the username as 'Deepali' on login page.

VulpesPosted Nov 28, 2012, 6:24 AM
string cmdstr = "select count(*) from [Registration] where UserName= '" + txtUsername.Text + "' ";