title: how to prevent duplicate username on signup page in asp.net
body: <p>i have 2 pages login and signup. and i am checking whether the username is available or not.and i have written a code  for it.but i can not prevent inserting of same username in database on signup button. How can I do that?</p>
  
  <p>here is my code on signup <code>page</code>. I have taken one <code>linkbutton</code> on sign up page-</p>
  
  <pre><code>protected void LinkButton1_Click1(object sender, EventArgs e)
  {
      conn.Open();
      cmd = new SqlCommand("select * from login where username='" + txtname.Text + "'", conn);
      dr = cmd.ExecuteReader();
      if (dr.Read())
      {
          Label1.Text = "Username already exists";
      }
      else
      {
          Label1.Text = "Username available";
      }
  }
  </code></pre>