title: Asp.net login script
body: <p>i'm new to asp.net, i'm writing a login &amp; registration script for learning database application. But the script seems not work. it stills can add duplicated username. Here is the script</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  using System.Configuration;
  
  public partial class Registration : System.Web.UI.Page
  {
      static string temp;
      protected void Page_Load(object sender, EventArgs e)
      {
          if (IsPostBack)
          {
              SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["earchConnectionString"].ConnectionString);
              con.Open();
              string cmdStr = "Select count(*) from [user] where UserName='" + TextBoxUN.Text + "'";
  
              SqlCommand userExist = new SqlCommand(cmdStr, con);
              int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
  
              con.Close();
              if (temp == 1)
              {
                  Response.Write("User Name Already Exist....&lt;br /&gt; Please Choose Another User Name.");
              }
          }
  
      }
      protected void Submit_Click(object sender, EventArgs e)
      {
  
          SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["earchConnectionString"].ConnectionString);
          con.Open();
          string insCmd = "Insert into [user] (UserName, Password, EmailAddress, FullName, level) values (@UserName,@Password,@EmailAddress, @FullName, @level)";
          SqlCommand insertUser = new SqlCommand(insCmd, con);
          insertUser.Parameters.AddWithValue("@UserName", TextBoxUN.Text);
          insertUser.Parameters.AddWithValue("@Password", TextBoxPass.Text);
          insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
          insertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text);
          insertUser.Parameters.AddWithValue("@level", level.SelectedValue.ToString());
  
          try
          {
              insertUser.ExecuteNonQuery();
              con.Close();
              //Response.Redirect("Login.aspx");
              Label1.Text = temp;
          }
          catch (Exception er)
          {
              Response.Write("Something wrong");
          }
          finally
          {
              //Any Special Action You Want To Add
          }
  
      }
  }
  </code></pre>
  
  <p>Any can detect the problems?</p>
  
  <p>thanks</p>