•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 375,210 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,240 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser:
Views: 145 | Replies: 0
![]() |
•
•
Join Date: Apr 2008
Posts: 30
Reputation:
Rep Power: 1
Solved Threads: 0
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
Other Threads in the VB.NET Forum
- Previous Thread: Export Data from listbox to Excel
- Next Thread: how to make a latest data appear after update it using an upadate button?


Linear Mode