Increment column in a table

bfsog

Well-known member
Joined
Apr 21, 2005
Messages
50
Location
UK
Programming Experience
5-10
Hi. When a button is pressed, I need to add 1 to a column, called Last_Break

I tried

VB.NET:
	    Me.OleDbUpdateCommand1.CommandText = "UPDATE users SET Last_Break=Last_Break+1 WHERE Username='" & sCurName & "'" '

It does not throw an error but the column is not updated.

Any ideas?

TIA
 
last_break is a field name and you cannot increment its value. for incrementing the values of a particular column use parameter object.

Me.OleDbUpdateCommand1.CommandText = "UPDATE users SET Last_Break=@Value WHERE Username='" & sCurName & "'" '

here @value is the parameter object. firstly, you will retrieve the last saved value in the last_break field, then u will increment the value by 1 and then pass the new value to @str through parameters collection of the command object.

cheers.
 
hi, but how to define the value? Dim value as String? How tp pass @str through parameters collection of the command object.

Regards
tiffany
 
Is the initial value of the column NULL? Or does Last_Break already contain a numeric value? What is the database and datatype?

(The SQL appears valid to me.)
 
Back
Top