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

        connection.Open()
        rowsEffected = cmd.ExecuteNonQuery()
        connection.Close()

    End Sub
UPDATE tblfirsthalf SET ShotsInsidePA = ShotsInsidePA + 1 WHERE PlayerNumber = 1
UPDATE `ontheball`.`tblfirsthalf` SET tblfirsthalf.ShotsInsidePA = tblfirsthalf.ShotsInsidePA +1 WHERE (((tblfirsthalf.PlayerNumber)=1));
Member Avatar for Unhnd_Exception

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 +

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.