title: Confused about how to check user exist or not
body: <p>I have a table with 4 columns  named  "ID","name","username","pass".what i am trying to do is that After the user enter username and password .XmlhttpRequest object returns a message something like user exist or not .But I am getting this exception at this line  </p>
  
  <pre><code>SqlDataReader dr = cmd.ExecuteReader();
  </code></pre>
  
  <p>exception message says </p>
  
  <pre><code>Incorrect syntax near 'hatca'.(thats the username)
  
  Unclosed quotation mark after the character string ''.
  </code></pre>
  
  <p>something wrong at this line</p>
  
  <pre><code> SqlCommand cmd = new SqlCommand("select * from userstable where username='" + username + "'AND pass='" + pass + "'",con);
  </code></pre>
  
  <p>everything looks fine to me  .What am i doing wrong here</p>
  
  <p>this is the all code
  aspx.cs</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
          if (Request.QueryString["ka"] != null &amp;&amp; Request.QueryString["pass"] != null)
          {
  
              string username = Request.QueryString["ka"];
              string pass = Request.QueryString["pass"];
              SqlConnection con = new SqlConnection("server=.\\sqlexpress;database=Projects;UID=sa;Password=1234");
              con.Open();
             SqlCommand cmd = new SqlCommand("select * from userstable where username='" + username + "'AND pass='" + pass + "'",con);
              //SqlCommand cmd = new SqlCommand("select * from userstable where username=@name and pass=@pass",con);
              //cmd.Parameters.AddWithValue("@name"
  
  
  
              SqlDataReader dr = cmd.ExecuteReader();
              if (dr.HasRows)
              {
  
                  Response.Write("exist");
              }
              else {
  
                  Response.Write("Doesntexist");
              }
              con.Close();
  
  
          }
          else {
              Response.Write("enter values");
  
          }
  
          Response.Close();
  
      }
  </code></pre>
  
  <p>and html page</p>
  
  <pre><code>    &lt;script src="Scripts/jquery-2.1.1.js"&gt;&lt;/script&gt;
     &lt;script type="text/javascript"&gt;
  
  
         function createXHR() {
  
             var xhr;
  
  
             try {
                 xhr = new XMLHttpRequest();
             } catch (e) {
  
             }
             return xhr;
         }
  
  
         function signIn() {
  
             var xhr = createXHR();
             var username=$('#txtusername').val();
             var pass=$('#txtpass').val()
  
             xhr.onreadystatechange=function(){
  
                 if(xhr!=null){
  
                     if(xhr.readyState==4){
  
                         if(xhr.status&gt;=200 &amp;&amp; xhr.status&lt;300){
  
                             var v = $('#result').html(xhr.responseText);
                             if (v == "exist") {
                                 $('#result').html("Done");
                             }
                             else if (v == "Doesntexist") {
  
                                 $('#result').html("Error");
                             }
                             else{
                                 $('#result').html(v);
  
                             }
  
                             }
  
                     }
  
                 }
                 else{
                     $('#result').html("Error");
  
  
                 }
             }
  
             xhr.open("GET", "Default.aspx?ka='" + username + "&amp;pass=" + pass, true);
             xhr.send(null);
         }
     &lt;/script&gt;
  </code></pre>