title: Not sure how to initialise the database connection
body: <p>I am trying to insert into my SQL database table called Questions, whenever I click on the button the error below comes up and I'm not sure how to solve this problem as I thought I only needed to open the database connection then close it afterwards? </p>
  
  <p>Any help would be very helpful.</p>
  
  <pre><code> private void button1_Click(object sender, EventArgs e)
      {
  
  
          string connectionString = ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString;
          SqlConnection connect = new SqlConnection(connectionString);
          connect.Open();
  
          SqlCommand command1 = new SqlCommand("INSERT INTO Questions ([Question Type]) VALUES (1)");
          command1.ExecuteNonQuery();
  
          connect.Close();
  
      }
  </code></pre>
  
  <blockquote>
    <p>An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll</p>
    
    <p>Additional information: ExecuteNonQuery: Connection property has not been initialized.</p>
  </blockquote>