title: How to connect to SQL Server using ADO.Net
body: <p>This is the first time I'm designing a web site. I'm having problem on connecting to my database. None of buttons work on pages. The most important one is Register button. I fill the form correctly but when I press Register button it doesn't register the new user into database. It even doesn't show any error message which I've considered. For example, it doesn't show that You've registered before or Your registration wasn't successful. No error message and no new record in my database. I've removed the captcha code because I thought that may cause problem.Here's my code:</p>
  
  <pre><code>using System;
  using System.Data.SqlClient;
  using System.Web.UI.WebControls;
  
  public partial class SignUp : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          string strname = Cache["TF"] as string;
          if (strname != null)
          {
              (Master.FindControl("Lozv") as Label).Text = strname;
              (Master.FindControl("LinkButton1") as LinkButton).Visible = true;
          }
          else
          {
              (Master.FindControl("Lozv") as Label).Text = "Guest";
              (Master.FindControl("LinkButton1") as LinkButton).Visible = false;
          }
  
      }
  
      protected void Button1_Click1(object sender, EventArgs e)
      {
          string username = txtboxUser.Text;
          SqlConnection sqlc = new SqlConnection("Data Source=.; Database=LDatabase; Integrated Security=True");
          SqlCommand cmd = new SqlCommand("SELECT dbo.CheckUserName(@UN)");
          cmd.Parameters.AddWithValue("@UN", txtboxUser.Text);
          sqlc.Open();
          Boolean User = Convert.ToBoolean(cmd.ExecuteScalar());
          sqlc.Close();
  
          if (User == false) ////////////// if user name is not in DB//////////////
          {
              SqlConnection sqlca = new SqlConnection();
              sqlca.ConnectionString = "data source=. ; database=LDatabase ; integrated security=true";
              SqlCommand cmda = new SqlCommand();
              cmda.Connection = sqlca;
              cmda.CommandText = "INSERT INTO User_Pass values(@UserName,@Pass,@Name,@LastName,@Email,@Date,@Sex,'0')";
              cmda.Parameters.AddWithValue("@UserName", txtboxUser.Text);
              cmda.Parameters.AddWithValue("@Pass", txtboxPass.Text);
              cmda.Parameters.AddWithValue("@Name", txtboxName.Text);
              cmda.Parameters.AddWithValue("@LastName", txtboxSurname.Text);
              cmda.Parameters.AddWithValue("@Email", txtboxEmail.Text);
              cmda.Parameters.AddWithValue("@Date", DateTime.Now);
              cmda.Parameters.AddWithValue("@Sex", rbtnGender.SelectedValue.ToString());
              cmd.Parameters.AddWithValue("@manager", "No");
  
              sqlca.Open();
              int n= cmda.ExecuteNonQuery();
              if (n &lt;= 0)
                  LMsg.Text = "Your registration wasn't successful";
              else
              {
                  txtboxName.Text = "";
                  txtboxSurname.Text = "";
                  txtboxUser.Text = "";
                  txtboxPass.Text = "";
                  txtboxRePass.Text = "";
                  txtboxEmail.Text = "";
                  rbtnGender.SelectedIndex = -1;
                  LMsg.Text = "You registered successfully.";
              }
              sqlca.Close();
          }
  
          else  //////////////if user name is in db//////////////
          {
              LMsg.Text = "This username has already registered.";
          }
      }
  }
  </code></pre>
  
  <p>Does Captcha have anything to do with this type of problem? Any help would be appreciated.</p>