连接到mysql并减少字段 [英] Connecting to mysql and decreasing a field
本文介绍了连接到mysql并减少字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,所有iam都使用vb.net 2010,我想使字段减少1,每次使用这里都是我的代码,但是它不起作用,请帮助
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 help
Imports 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'
所有操作都将用户"表中所有记录的用户名"设置为管理员".当前信用"为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.
这篇关于连接到mysql并减少字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文