title: Insert data into database table with text box
body: <p>I'm trying to insert data into a table and the code snipplet I saw seems to work for that person but for me!
  I don't know what I'm doing wrong because I don't know database handling for asp.net. Can someone please tell me whats wrong with the code?</p>
  
  <pre><code>public partial class CompanyLogin : System.Web.UI.Page
  {
  protected void Button1_Click(object sender, EventArgs e)
  {
      OdbcConnection conn = new OdbcConnection();
      conn.ConnectionString = @".\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VCtemps.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
  
      string sql = "insert into company values(@CompName, @BusinessType, @Pword)";
      OdbcCommand cmd = new OdbcCommand(sql);
      string CompName = txtCompName.Text;
      string BusinessType = DropDownList1.Text;
      string Pword = txtPassword.Text;
      cmd.Connection = conn;
  
      cmd.CommandText = "insert into company(CompName, BusinessType, Pword) Values(@CompName,@BusinessType,@Pword);";
      cmd.Parameters.AddWithValue("@CompName",SqlDbType.VarChar);    
      cmd.Parameters.AddWithValue("@BusinessType",SqlDbType.VarChar);    
      cmd.Parameters.AddWithValue("@Pword",SqlDbType.VarChar);    
  
  cmd.ExecuteNonQuery();
  
      conn.Close();
  
      txtCompName.Text = "";
      txtPassword.Text = "";
      DropDownList1.Text = "";
  }
  }
  </code></pre>
  
  <p>I fixed the code thanks to you guys but when I run it or when I click the register button I get the following error</p>
  
  <p>ExecuteNonQuery requires an open and available Connection. The connection's current state is closed</p>