G
Guest
Hi,
I am using parameters to preform an INSERT. This is my first time. Here is
what I have:
Dim myConnection As New SqlConnection("User ID=sa;Password=sappkg;Initial
Catalog=PSC;Data Source=CSIREPL;")
Dim insertCommand As SqlCommand = myConnection.CreateCommand
insertCommand.CommandText = "INSERT INTO tblInventory (ItemNum,
Quantity) VALUES(?,?)"
insertCommand.Parameters.Add(New SqlParameter("ItemNum",
SqlDbType.NText, 20))
insertCommand.Parameters.Add(New SqlParameter("Quantity",
SqlDbType.NText, 10))
insertCommand.Parameters("ItemNum").Value = Me.txtDcdData.Text
insertCommand.Parameters("Quantity").Value = Me.txtQuantity.Text
Try
myConnection.Open()
insertCommand.ExecuteNonQuery()
myConnection.Close()
Catch ex As SqlException
MessageBox.Show("Unable to open connection. Reason: " &
ex.Errors(0).Message)
Exit Sub
End Try
When I run it, it throws an exception that says,
"Incorrect syntax near 'ItemNum'.
I can't get it figured out, any help?
Thanks,
Steve
I am using parameters to preform an INSERT. This is my first time. Here is
what I have:
Dim myConnection As New SqlConnection("User ID=sa;Password=sappkg;Initial
Catalog=PSC;Data Source=CSIREPL;")
Dim insertCommand As SqlCommand = myConnection.CreateCommand
insertCommand.CommandText = "INSERT INTO tblInventory (ItemNum,
Quantity) VALUES(?,?)"
insertCommand.Parameters.Add(New SqlParameter("ItemNum",
SqlDbType.NText, 20))
insertCommand.Parameters.Add(New SqlParameter("Quantity",
SqlDbType.NText, 10))
insertCommand.Parameters("ItemNum").Value = Me.txtDcdData.Text
insertCommand.Parameters("Quantity").Value = Me.txtQuantity.Text
Try
myConnection.Open()
insertCommand.ExecuteNonQuery()
myConnection.Close()
Catch ex As SqlException
MessageBox.Show("Unable to open connection. Reason: " &
ex.Errors(0).Message)
Exit Sub
End Try
When I run it, it throws an exception that says,
"Incorrect syntax near 'ItemNum'.
I can't get it figured out, any help?
Thanks,
Steve