You have no space between WHERE ID = '" & ID.Text & "'
and "SET Date = '"
(The vbcrlfs don't really translate across to Sql when you send it). You may also have something in your textboxes with an apostrophe inside it, which is causing one of the sql strings to terminate early.
For this reason (and so it can't be hacked via Sql Injection) you should use SqlParameter
s.
Imagine this, for instance. I enter ';Truncate Table main;'
into _date.Text. Your query suddenly looks like this:
Update main Set Date = ''; Truncate Table main;'', Artist = '', City = '', venue = '', where id = ''
Most of that will fail, but Truncate Table main
is likely to execute and clear your data.
To get around this, use SqlParameter
:
Dim conn As New SqlConnection()
Dim cmd As New SqlCommand
cmd.Parameters.Add(New SqlParameter("ID", ID.Text))
cmd.Parameters.Add(New SqlParameter("Date", _date.Text))
cmd.Parameters.Add(New SqlParameter("Artist", artist.Text))
cmd.Parameters.Add(New SqlParameter("City", City.Text))
cmd.Parameters.Add(New SqlParameter("Venue", venue.Text))
cmd.Connection = conn
cmd.CommandText = "UPDATE main " & vbCrLf & _
"SET Date = @Date, " & vbCrLf & _
"Artist = @Artist, " & vbCrLf & _
"City = @City, " & vbCrLf & _
"Venue = @Venue " & vbCrLf & _
"WHERE ID = @ID"
cmd.ExecuteNonQuery()