Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Pretty much what the error message implies - the Connection property of the SqlCommand object hasn't been assigned to the connection you opened (in this case you called it <code>myConnection</code>).</p> <p>Also, a word of advice here. Do some reading on sql parameters - doing sql concatenation from user input without any sanity checks is the way <a href="http://en.wikipedia.org/wiki/SQL_injection" rel="nofollow">SQL injection</a> attacks happen. </p> <p>This is one way to do it:</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, " &amp; _ " EnterDate, CatID, RackID, Amount) " &amp; _ "VALUES(@bookCode, @bookTitle, @author, @publishingYear, @price, @enterDate, " &amp; _ " @catId, @rackId, @amount)") myCommand.Connection = myConnection with myCommand.Parameters .AddWithValue("bookCode", txtBookCode.Text) .AddWithValue("bookTitle", txtTitle.Text) .AddWithValue("author", txtAuthor.Text) .AddWithValue("publishingYear", txtPublishYear.Text) .AddWithValue("price", txtPrice.Text) .AddWithValue("enterDate", txtEnterDate.Text) .AddWithValue("catId", txtCategory.Text) .AddWithValue("rackId", txtRack.Text) .AddWithValue("amount", txtAmount.Text) end with 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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload