title: An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll when I tried to insert data into textbox
body: <p>i am creating a connection to my database from from visual studio.</p>
  
  <p>this is my 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;
  
  
  public partial class CM : System.Web.UI.Page
  {
      SqlConnection con = new SqlConnection("server =KIRITI; database =msdb; Integrated Security=True");
  
  protected void Button1_Click(object sender, EventArgs e)
  {
      con.Open(); 
      String NotesMaker = TextBox1.Text;
      SqlCommand cmd = new SqlCommand("Insert into NOTESMAKER(NOTESMAKER) Values('"+NotesMaker+"',con)");
      cmd.ExecuteNonQuery();
      cmd.CommandText = "Select@@Identity";
      con.Close();
  }
  }
  </code></pre>
  
  <p>I get an error at command.Executenonquery(): An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code</p>
  
  <p>Additional information: ExecuteNonQuery: Connection property has not been initialized.</p>
  
  <p>Please help!! I'm blocked from two days!!</p>