I"m confused on how to prevent SQL injection, I've looked online. Do I use a store procedure, or do I Create variables, Im just completely lost.
Try
connection.Open()
’we got here so our connection to the db is sound
chosen = cboBooks.SelectedIndex
id = customerList(cboCustomers.SelectedIndex)
isbn = isbnList(cboBooks.SelectedIndex)
If number <= qty Then
Dim sql As String
sql = "INSERT INTO purchase(customer_id, ISBN, store_id, quantity)
VALUES(" & id & ", " & isbn & ", 1, " & number & ");"
Dim cmd As New SqlCommand(sql, connection)
Dim rows As Integer
rows = cmd.ExecuteNonQuery()
If rows >= 1 Then
’now update the inventory to reflect a sale
sql = "UPDATE inventory SET quantity = (quantity -" & number & ")
WHERE inventory.ISBN = " & isbn & " AND store_id = 1"
’define and execute the query command
Dim cmd2 As New SqlCommand(sql, connection)
rows = cmd2.ExecuteNonQuery