gabanxx 0 Light Poster

i've create a program that contain a 4 textbox and three action button. the textbox are used to fill user name, date of birth, hobbies and number. while the action button are submit upadte and clear...all of this are working perfectly..i also manage to store all the data entered by user in sql server 2000 db. the data also will display itself when the program started. the problem is now when i want to update the data i had to close te program first and start it back then the updated data will appear. what i want is the data will be outomatically updated when i click the update button. i really seek help here i hope my problem is clear enough...plzzzz oo want more thing i want to add a delete button that will outomatically delete the data...below is the program i'have being working on...i hope anyone out there reading this threat can help me solve the problem...im just a nwbz... i will apreciate alot any help...thanks in advance.....


this is use to update the data
Private Sub Update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim varCommand As New SqlCommand

Dim varAdapter As SqlDataAdapter

Try
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1") 'STEP 1
varConnection.Open()
varQuery = "UPDATE tbl_rop SET Name_User ='" & Trim(TextBox1.Text) & "', Date_of_birth= '" & Trim(TextBox2.Text) & "' , Hobbies='" & Trim(TextBox3.Text) & "' , Phone_Number ='" & Trim(TextBox4.Text) & "' where Name_User = '" & Trim(TextBox1.Text) & "'"
varCommand = New SqlCommand(varQuery, varConnection)
varCommand.CommandTimeout = 9999 'STEP 4
varCommand.ExecuteNonQuery() 'STEP 5

varCommand.Dispose() 'STEP 6
varConnection.Close() 'STEP 7

Catch ex As Exception
varConnection.Open()
'varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1")

Dim sql As String
sql = "SELECT * FROM tbl_rop"
'varCommand = New SqlCommand(sql, varConnection)
varAdapter = New SqlDataAdapter(varCommand)


varAdapter.Fill(varDataSet)
TextBox1.Text = varDataSet.Tables(0).Rows(0).Item("Name_User")
TextBox2.Text = varDataSet.Tables(0).Rows(0).Item("Date_of_birth")
TextBox3.Text = varDataSet.Tables(0).Rows(0).Item("Hobbies")
TextBox4.Text = varDataSet.Tables(0).Rows(0).Item("Phone_Number")

varConnection.Close()

End Try

End Sub

this is used to delete the data which nothing seem to be working help mw find the problem


Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MsgBox("are you sure want to delete?, important information will be erase. ")
varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1") 'STEP 1
varConnection.Open() 'STEP 2
varQuery = "DELETE FROM tbl_rop WHERE Name_User ='" & TextBox1.Text & "', Date_of_birth= '" & TextBox2.Text & "' , Hobbies='" & TextBox3.Text & "' , Phone_Number ='" & TextBox4.Text & "'" 'STEP 3
varCommand = New SqlCommand(varQuery, varConnection)

varCommand.ExecuteNonQuery()

varCommand.Dispose() 'STEP 6
varConnection.Close() 'STEP 7

End Sub