4 Replies - 1848 Views - Last Post: 11 May 2011 - 12:07 PM Rate Topic: -----

#1 jcesz12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-April 11

having trouble with updating vb.net

Posted 10 May 2011 - 05:45 PM

i'm using vb.net and i'm having trouble in updating the user. i have textbox for username,password and confirm password. i also have datagridview. when i edit a user then clicks the update button, all the previous account will be updated with the one that i updated last.(i provided a print screen for u guys to understand)and also here's the code. please help me and tell me my mistakes. thank you i'm just new in vb.net

Attached Image


 Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click

        Dim connstring = New SqlClient.SqlConnection
        Dim cmd = New SqlClient.SqlCommand
        'Dim adapt = New SqlClient.SqlDataAdapter("select Username, Password from tbl_user", connstring)
        Dim dset As DataSet = New DataSet

        If txtpassword.Text <> txtconfirm.Text Then
            MsgBox("Password not the same")

        Else

            connstring.ConnectionString = "Data Source=MISD-ASBAUTISTA\SQLEXPRESS;Initial Catalog=inventory system;Integrated Security=SSPI;"
            connstring.Open()
            cmd.Connection = connstring
            cmd.CommandText = "UPDATE tbl_user SET [email protected],password = @password "
            cmd.Parameters.AddWithValue("@username", Me.DataGridView1.Columns)
            cmd.Parameters.AddWithValue("@password", Me.DataGridView1.Rows)

            cmd.Parameters("@username").Value = txtusername.Text
            cmd.Parameters("@password").Value = txtpassword.Text


            cmd.ExecuteNonQuery()

            MsgBox("Account has been updated!", MsgBoxStyle.Exclamation, "UPDATE")
            '  adapt.Fill(dset, "tbl_user")
            With DataGridView1
                ' .DataMember = "tbl_user"
                '.DataSource = dset.DefaultViewManager
                .Refresh()
                .Update()
            End With

            connstring.Close()
            txtconfirm.Text = ""
            txtpassword.Text = ""
            txtusername.Text = ""
        End If
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: having trouble with updating vb.net

#2 jcesz12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-April 11

Re: having trouble with updating vb.net

Posted 10 May 2011 - 06:10 PM

help me please.. tnx
Was This Post Helpful? 0
  • +
  • -

#3 jcesz12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-April 11

Re: having trouble with updating vb.net

Posted 10 May 2011 - 07:49 PM

..
Was This Post Helpful? 0
  • +
  • -

#4 jcesz12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 27-April 11

Re: having trouble with updating vb.net

Posted 10 May 2011 - 10:18 PM

someone please
Was This Post Helpful? 0
  • +
  • -

#5 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1822
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: having trouble with updating vb.net

Posted 11 May 2011 - 12:07 PM

FIRST: Dont reply to your self if no need for that.!
Your proplem is this query:
"UPDATE tbl_user SET [email protected],password = @password "
 

It needs WHERE clause, to be:
"UPDATE tbl_user SET [email protected],password = @password  WHERE ..."

This will be accomplished if your table has primary key column!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1