Click here to Skip to main content
15,890,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 17-Jan-11 8:57am
v3
Comments
Yusuf 17-Jan-11 14:58pm    
a. You have been warned off not disclosing username/password.
b. The code you presented looks similar to an answer someone gave your in your earlier QA post.
c. If you don't understand the answer, ask the question in the same question, rather than creating a new one.

Why would you expect that code to reduce a field by any amount:
SQL
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.
 
Share this answer
 
Comments
Espen Harlinn 17-Jan-11 15:08pm    
5+ and this might be useful http://www.w3schools.com/sql/sql_update.asp
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900