Visual Studio 2012 (Databese Connectivity)

Jan 21 2015 10:46 PM

 

I am getting the follpwing error

Error:System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near the keyword 'where'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection

I have writtrn the code for connction as

SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
            con.Open();
            string checkuser = "select count(*) from Userdata where Username = '" + txtUserName.Text + "'";
            SqlCommand com = new SqlCommand(checkuser, con);
            int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
            if (temp == 1)
            {
                Response.Write("User Already Exists");
            }

Answers (4)