Thomas Roesen
Thomas Roesen

Reputation: 73

MySQL doesn't show new data

Hello

I have encountered a problem I can't seem to wrap my head around.

I have a database with a table called

Customer - CustomerID(primary key), Firstname, Surname, Address, Zipcode and sex. it is filled with 512 rows.

I've created a small application in VB where you can fill out a form with that information and then click a button to register the new customer. Here is a sample of the code:

 Private Sub save(ByRef SQLStatement As String)
    If minConnection.State = ConnectionState.Closed Then
        myConnection.Open()
    End If

    With minCommand
        .CommandText = SQLStatement
        .CommandType = CommandType.Text
        .Connection = minConnection
        .ExecuteNonQuery()
    End With

    MsgBox("Saved to Database", MsgBoxStyle.Exclamation, "Saved!")
    myConnection.Close()
    myConnection.Dispose()

End Sub
Private Sub cmdCustomer_Click(sender As Object, e As EventArgs) Handles cmdCustomer.Click

    myConnection.Open()

    If rbW.Checked = True Then
        sex = "W"
    Else
        sex = "M"
    End If

    Dim newCustomer As String = ("insert into customer(CustomerID, Firstname, Surname, Address, Zipcode, Sex) VALUES(" & txtCustomerID.Text & ", '" & txtFirstname.Text & "', '" & txtSurname.Text & "', '" & txtAddress.Text & "', " & txtZipcode.Text & ", '" & sex & "')")
    save(newCustomer)

End Sub

In my experience this should do the job, but for some reason I can't see the new entry in my database. However, if I try to create a new customer with the same CustomerID, I get an error message saying something like Duplicate Entry. With that message I know the data should've been inserted. To test it further I created a datagridview with the sql-statement: Select * from customer. The datagridview did show my newly registered customers!

With all this in mind, I believe the problem lies within MySQL Workbench and not my code or even Visual Basic. Although, I can't seem to find out how to fix this problem. Am I far out here? Is it just a stupid mistake?

Excuse my English, it's not my first language, and also my code as it is very amateur-ish. Thank you in advance for whatever input you guys have.

Upvotes: 1

Views: 136

Answers (1)

kvambaam
kvambaam

Reputation: 496

To solve this you have to run a ‘rollback’.

Upvotes: 2

Related Questions