Deepali Patil

Deepali Patil

  • NA
  • 142
  • 54.7k

Hi...I am trying to solve this error but m not able to.

Nov 28 2012 6:17 AM
This is my code :

 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.

Answers (1)