Results 1 to 17 of 17

Thread: Decreasing a field

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Decreasing a field

    hi all am using vs2010
    here is my connection string
    Code:
    Dim MySQLConnection As MySqlConnection
            MySqlConnection = New MySqlConnection
            MySQLConnection.ConnectionString = "server=db4free.net;Port=3306; User ID=seifhatem; password=11; database=huaweiunlocking"
            MySqlConnection.Open()
    
            Dim MyAdapter As New MySqlDataAdapter
            Dim SqlQuary = "SELECT * From Users WHERE Username='" & usernametextbox.Text & "' AND password = '" & passwordtextbox.Text & "';"
            Dim Command As New MySqlCommand
            Command.Connection = MySqlConnection
            Command.CommandText = SqlQuary
            MyAdapter.SelectCommand = Command
            Dim Mydata As MySqlDataReader
            Mydata = Command.ExecuteReader
            If Mydata.HasRows = 0 Then
                MsgBox("Error During Login:Please Enter Valid Data")
            Else
    
            End If
    I want a command that decreases the field called Credits in the database and i will write between else and end if
    like if the user clicks the button it connects and decrease 1 credit thx in advance

  2. #2
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Decreasing a field

    What is the structure of the table?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    ID,Username,Password and Credit(which i want yo decrease it)
    Thx in asvance

  4. #4
    Lively Member
    Join Date
    Jul 2010
    Posts
    86

    Re: Decreasing a field

    What is the datatype of credit? So you're wanting to do an update statement to decrease by 1 every record returned by SqlQuary? Am I understanding your need correctly?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    Yes u'r right and the type is varchar

  6. #6
    Lively Member
    Join Date
    Jul 2010
    Posts
    86

    Re: Decreasing a field

    is there a reason you're not using an integer datatype? it just holds numeric data, correct?

  7. #7
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Decreasing a field

    So you need to use an update query to decrease by one and as gtrahern suggested you may be better of using some numeric type.
    So what is the problem you have?
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    Ok and after changing it to integer
    How can i edit it using vb.net

  9. #9
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Decreasing a field

    Quote Originally Posted by salmawy View Post
    Ok and after changing it to integer
    How can i edit it using vb.net
    Fetch the value to a variable.
    Update the value of the variable by subtracting 1 from it.
    Update the table with the value of the variable.

    Do you want the code for this?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    What is thecode to do these things

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    Because this is my first time to work with sql

  12. #12
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Decreasing a field

    Quote Originally Posted by salmawy View Post
    What is thecode to do these things
    Running an update statement is the easiest way to do it.

    UPDATE USERS SET CREDIT = CREDIT -1 WHERE USERNAME = 'USER'

    You'll need to replace some of the values in the sql statement. To figure out how to execute this statement, look up the tutorials on this forum.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    Do i need to excute it using
    Sql qyary

  14. #14
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Decreasing a field

    Quote Originally Posted by salmawy View Post
    Do i need to excute it using
    Sql qyary
    To execute this SQL Query, you'll need a connection string, a command object and a parameter object.
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  15. #15
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    137

    Re: Decreasing a field

    I am usingmysql connecter/net 6.0.7 as refrence and the connection string is in post 1 i did the connection

  17. #17
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: Decreasing a field

    I don't think there are many differences.
    Just use a mysql tutorial.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width