I'm having some problems with the UPDATE statement in VB.NET. Not the UPDATE statement directly, but when it comes to incrementing a field's value by 1.
Below is the code that I'm using for writing to the database, as well as the two UPDATE SQL statements that I've tried.

Any help would be appreciated...

Private Sub updateRecord(ByVal query As String)

        Dim connection As New MySqlConnection(connStr)
        Dim cmd As New MySqlCommand(query, connection)
        Dim rowsEffected As Integer = 0

        rowsEffected = cmd.ExecuteNonQuery()

    End Sub
UPDATE tblfirsthalf SET ShotsInsidePA = ShotsInsidePA + 1 WHERE PlayerNumber = 1
UPDATE `ontheball`.`tblfirsthalf` SET tblfirsthalf.ShotsInsidePA = tblfirsthalf.ShotsInsidePA +1 WHERE (((tblfirsthalf.PlayerNumber)=1));
7 Years
Discussion Span
Last Post by GeekByChoiCe

I see nothing wrong with your Update Statement.

Just for fun and games try:

UPDATE tblfirsthalf SET ShotsInsidePA = (ShotsInsidePA + 1) WHERE PlayerNumber = 1

And for more fun. Make sure ShotsInsidePA is not null


Just tried that too. Doesn't seem to be working either. Also, ShotsInsidePA isn't null either.

Not sure what the problem is... It seems to work perfectly well with every other SQL statement.


just a blue shot...
UPDATE tblfirsthalf SET ShotsInsidePA = CInt(ShotsInsidePA) + 1 WHERE PlayerNumber = 1

if im not mistaken the sql statement dont know the datatype of a field. so it takes by default string, which have different behave on a operator like +

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.