I have followed a tutorial at http://www.vbmysql.c...mysql-tutorials. It is a very good tutorial but it is also a little dated. Most people who visit it praise it to high heaven so I decided it was a good place to start as an absolute beginner to programming. (I have teamed it up with Dan Mabbut Vis basic tutorial at about.com and joined DreamInCode in order to learn what I can accomplish with Visual Basic 2008 Express ). I am up to part 6 of 7 but keep going back to part 4 because there is one aspect I just cant work out.
I am creating a form which logs staff in or out of work and allows staff to include a message with their ( at work /away from work ) status details on the form.
Everything works as it should apart from one thing:
The form is supposed to update a users status in a new row when they click a button. In my form the rows per user are being over-written with the updated information - it is not being written in a new row. There is a login form which precedes the staff status form - this has a little relevant code re calling the user info from the database but I think my problem is related to the insert statement in the middle of the below code.
Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click Dim conn As New MySqlConnection Dim myCommand As New MySqlCommand conn.ConnectionString = myConnString myCommand.Connection = conn <!--HERE--> myCommand.CommandText = "INSERT INTO event(user_id, message_id, timestamp, status, creator)" _ & "VALUES(?UserID, ?MessageID, NOW(), ?Status, ?Creator)" myCommand.Parameters.Add("?UserID", myUserID) myCommand.Parameters.Add("?MessageID", cboMessage.SelectedValue) myCommand.Parameters.Add("?Status", cboStatus.SelectedItem) myCommand.Parameters.Add("?Creator", myUserID) Try conn.Open() myCommand.ExecuteNonQuery() Catch myerror As MySqlException MsgBox("There was an error updating the database: " & myerror.Message) End Try End Sub
My code has changed quite a bit since the above as the form has progressed but the problem started at the stage above and has not changed with the forms progression. Every other aspect of staff update info is working well in my form - just not in a new row.
I am going bald - The tutorial was written for VB2005 Express - I am using VB2008 Express though it has not made too much difference to the tutorial. Does anyone know if any changes have been made to Visual Basic 2008 Express which might answer my question or does anyone have any other ideas of what may be wrong.
Being my first lesson I would really like to finish it properly. I am very grateful for any help.
(Hopefully will be starting one of DreamInCodes tutorials v soon - am currently searching through all your beginners posts for help with learning ideas.)