title: VB.NET SQL Server Insert - ExecuteNonQuery: Connection property has not been initialized
body: <p>In the form load event, I connect to the SQL Server database:</p>
  
  <pre><code>Private Sub AddBook_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
              myConnection = New SqlConnection("server=.\SQLEXPRESS;uid=sa;pwd=123;database=CIEDC")
              myConnection.Open()
  
  End Sub
  </code></pre>
  
  <p>Here in the Insert event, I use the following code:</p>
  
  <pre><code>Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
              Try
                  myConnection.Open()
                  myCommand = New SqlCommand("INSERT INTO tblBook(BookCode, BookTitle, Author, PublishingYear, Price, EnterDate, CatID, RackID, Amount) VALUES('" &amp; txtBookCode.Text &amp; "','" &amp; txtTitle.Text &amp; "','" &amp; txtAuthor.Text &amp; "','" &amp; txtPublishYear.Text &amp; "','" &amp; txtPrice.Text &amp; "', #" &amp; txtEnterDate.Text &amp; "#, " &amp; txtCategory.Text &amp; "," &amp; txtRack.Text &amp; "," &amp; txtAmount.Text &amp; ")")
                  myCommand.ExecuteNonQuery()
                  MsgBox("The book named '" &amp; txtTitle.Text &amp; "' has been inseted successfully")
                  ClearBox()
              Catch ex As Exception
                  MsgBox(ex.Message())
              End Try
              myConnection.Close()
  End Sub
  </code></pre>
  
  <p>And It produces the following error:</p>
  
  <pre><code>ExecuteNonQuery: Connection property has not been initialized
  </code></pre>