我如何使用积分。 [英] How Do I Use Credits.
问题描述
这是故事
我有一个Mysql数据库设置:
表帐户:< br $> b $ b
Id:1
姓名:Donny
积分:600
我写了一个带按钮的代码购买
现在我在按钮上这个代码很平静:
Here is the story
I have a Mysql database setup:
Table Accounts:
Id: 1
Name: Donny
Credits: 600
and i have write a code with a button call's Buy
now i have on the button this little peace of code:
If credits.Text <= 0 Then
MsgBox("Geen credits meer.")
Else
Dim conn As MySqlConnection
conn = New MySqlConnection
conn.ConnectionString = "server=xxx;port=3306; user id=xxx; password=xxx; database=xxx"
Try
conn.Open()
Catch myerror As MySqlException
MsgBox("error connecting to database")
End Try
Dim myadapter As New MySqlDataAdapter
Dim sqlquery = "UPDATE account SET credits = credits -700 WHERE id='" & Trim(id.Text) & "'"
Dim mycommand As New MySqlCommand()
mycommand.Connection = conn
mycommand.CommandText = sqlquery
myadapter.SelectCommand = mycommand
mycommand.ExecuteNonQuery()
Try
conn.Close()
Catch myerror As MySqlException
MessageBox.Show("Cannot connect to database: " & myerror.Message)
Finally
conn.Dispose()
End Try
End If
现在举个例子我在我的账户上有600个积分。
并想购买一件产品,它需要700.现在我想要的是系统说它不可能,因为你只有600个学分..现在我已经编写了一个代码,如果它的null然后它显示一个消息框但是会是什么发生的是它显示我的值:-100然后如果我再次点击它然后它显示msg框。
如何编辑这个代码的和平它将发生我想要的是什么。
Now for a example i have on my account 600 credits.
and wanna buy a product it cost 700. now what i want is that the system says its not possible because you got only 600 credits .. now i have write a code that if its null then it show a message box but what is gonna happened is it show me the value: -100 and then if i click again then it shows the msg box.
How i must edit this peace of code its gonna happened what i want.
推荐答案
为什么这背后的逻辑如此困难?
所有你做的就是在数据库中查询用户记录及其帐户余额。检查是否有足够的学分。如果有另一个数据库查询需要用新余额更新用户记录,可能还有另一个查询来记录事务。
Why is the logic behind this so difficult?
All you do is query the database for the user record and his account balance. Check to see if there is enough credits. If there is another database query is required to update the user record with the new balance and probably another query to record the transaction.
这篇关于我如何使用积分。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!