4 Replies - 469 Views - Last Post: 05 October 2012 - 10:42 AM Rate Topic: -----

#1 Crystalz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-October 12

Editing Database Tables Question/Problem.

Posted 05 October 2012 - 10:08 AM

Hello, i'm trying to make my program change a value in a database.
I've got a database called Account, and a Table called Accounts. I have 4 columns in this table. Id(Key column), UserName, Password and Adminpower.
What I am trying to do is to make a button change a value in that table. What I do not know is how to make the program know which row i want to change the value in.


    Private Sub btnAdmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdmin.Click
        Dim cmd As SqlCommand
        Dim reader As SqlDataReader
        con = New SqlConnection(_connectionString)
        cmd = con.CreateCommand()
        con.Open()
        cmd.CommandText = "ALTER Accounts ('Adminpower') VALUES('1')"
        reader = cmd.ExecuteReader()
        If Not reader.HasRows Then
            MessageBox.Show("Something is wrong.")
        End If
    End Sub


That's the code so far for the button. So what I want it to do is to change the Adminpower column from 0 to 1 when pressing that button. Yes I have already connected it to the database.
When I try to press the button I get an error saying that the table doesn't exist.


Any help is appreciated.
Thanks

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Editing Database Tables Question/Problem.

#2 Crystalz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-October 12

Re: Editing Database Tables Question/Problem.

Posted 05 October 2012 - 10:14 AM

I'm sorry about the large image. I can't find the edit button. If there is one that is.
Was This Post Helpful? 0
  • +
  • -

#3 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Editing Database Tables Question/Problem.

Posted 05 October 2012 - 10:26 AM

In your cmd.Text, you need to tell WHERE you want to UPDATE the table row. For example: UPDATE 'Accounts' SET 'Adminpower' = 1 WHERE 'UserName' = "YourUserName" AND 'Password' = "YourPassword". Later you might want to look at parameterized queries.
Was This Post Helpful? 1
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1052
  • View blog
  • Posts: 4,077
  • Joined: 02-July 08

Re: Editing Database Tables Question/Problem.

Posted 05 October 2012 - 10:27 AM

It looks like you need an Update statement. SQL Examples
Was This Post Helpful? 0
  • +
  • -

#5 Crystalz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-October 12

Re: Editing Database Tables Question/Problem.

Posted 05 October 2012 - 10:42 AM

View Postlucky3, on 05 October 2012 - 10:26 AM, said:

In your cmd.Text, you need to tell WHERE you want to UPDATE the table row. For example: UPDATE 'Accounts' SET 'Adminpower' = 1 WHERE 'UserName' = "YourUserName" AND 'Password' = "YourPassword". Later you might want to look at parameterized queries.


Thank you! I got it working by editing your post a little. It worked with

UPDATE Accounts SET Adminpower = 1 WHERE '" & TextBox1.Text & "' = ""UserName"" AND '" & TextBox2.Text & "' = ""Password"""

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1