mysql减少字段,连接到mysql并减少字段

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值