hey all iam using vb.net 2010 and i want to make a field decreased by 1 each use here is my code but it''s not working please helpImports MySql.Data.MySqlClient
Public Class Form1
Private connStr As String = "Database=huawiunlocking;" & _
"Data Source=********;" & _
"User Id=**********;Password=*********;" & _
"Connection Timeout=20"
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Console.WriteLine(updateRecord("UPDATE Users SET Username=''Admin'' WHERE Credits =''10''"))
End Sub
Function updateRecord(ByVal query As String) As Integer
Try
Dim rowsEffected As Integer = 0
Dim connection As New MySqlConnection(connStr)
Dim cmd As New MySqlCommand(query, connection)
connection.Open()
rowsEffected = cmd.ExecuteNonQuery()
connection.Close()
Return rowsEffected
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Function
End Class
Thanks in advance
解决方案
Why would you expect that code to reduce a field by any amount:
UPDATE Users SET Username='Admin' WHERE Credits ='10'
All that does is set the "Username" of all records in the "Users" table which currently have a "Credits" of 10 to "Admin".
No numeric values are altered at all.
UPDATE Users SET Credits=Credits-1
provided that Credits is not a string as shown in your sample.
Or let us know more about the data structure being used and which field you want to update.