title: How to insert record into a sql server express database table?
body: <p>I'm trying to insert a textbox value to a database table called <code>site_list</code>.</p>
  
  <p>The <code>site_list</code> table contains two columns <code>id</code> and <code>site_name</code>, <code>id</code> set to auto increment</p>
  
  <p>This is the code I'm trying and when it execute there is no error, but the data is not showing up in the table</p>
  
  <pre><code>SqlConnection conn = new SqlConnection();
  conn.ConnectionString =
               "Data Source=.\\SQLExpress;" +
               "User Instance=true;" +
               "Integrated Security=true;" +
               "AttachDbFilename=|DataDirectory|scraper_db.mdf;";            
  
  SqlCommand addSite = new SqlCommand("INSERT INTO site_list (site_name) "
       + " VALUES (@site_name)", conn);
  
  addSite.Parameters.Add("@site_name", SqlDbType.NVarChar).Value = textBox1.Text;
  
  conn.Open();
  addSite.ExecuteNonQuery();
  conn.Close();
  </code></pre>
  
  <p>Any help would be appreciated.</p>
  
  <p>Regards</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This code started to work </p>
  
  <pre><code>    string connstring = "Data Source=.\\SQLExpress;"+
                          "Integrated Security=true;"+
                          "User Instance=true;"+
                          "AttachDBFilename=|DataDirectory|scraper_db.mdf;"+
                          "Initial Catalog=scraper_db";
  
      using (SqlConnection connection = new SqlConnection(connstring))
      {
          connection.Open();
          SqlCommand addSite = new SqlCommand("INSERT INTO site_list (site_name)"+
                               "VALUES (@site_name)", connection);
          addSite.Parameters.AddWithValue("@site_name", textBox1.Text); 
          addSite.ExecuteNonQuery();
          connection.Close();
      }
  </code></pre>