title: How to connect an Sql server database in a user control in Umbraco?
body: <p>I am a newbie in Umbraco. I am trying to develop a custom registration page in umbraco using dot net User control. For that, I have created a custom table named "registerTable" in umbraco database. I just want to insert the data in to that table using the Usercontrol. . The connection string "CM_Connection" is in the Webconfig file.</p>
  
  <p>This is the code</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;
  
  namespace thesis
  {
         public partial class test : System.Web.UI.UserControl
         {
            protected void Page_Load(object sender, EventArgs e)
            {
            }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
                  using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CM_Connection"].ConnectionString))
                  {
                      SqlCommand cmd = new SqlCommand();
                      Guid guid;
                      guid = Guid.NewGuid();
                      string sql = "INSERT INTO registerTable (Firstname) VALUES (@Name)";
                      cmd.Parameters.AddWithValue("@Name", TextBox1.Text.Trim() );
                      cmd.Connection = con;
                      cmd.CommandText = sql;
                      con.Open();
                      try
                      {
                          cmd.ExecuteNonQuery();
                          Label1.Text = "Registered successfully.";
                      }
                      catch (Exception ex)
                      {
                          throw new Exception(ex.Message);
                      }
                  }
          }
      }
  }
  </code></pre>