|
-
Sep 3rd, 2018, 12:07 AM
#1
Thread Starter
Member
[RESOLVED] Issuing with updating textbox data in visual studio linked to mysql database
Hello,
I am using a MySQL database which is connected to Visual Studio Community Edition 2017. I have a TabControl Form with several tabs in it. I have used the following vb.net code to update textbox data: -
Private Sub btnEmployeeUpdateDetails_Click(sender As Object, e As EventArgs) Handles btnEmployeeUpdateDetails.Click
If incrementdecrement = -1 Then
incrementdecrement = 0
End If
Dim conn As New MySqlConnection
conn.ConnectionString =
"server=localhost;Port=3306;database=winery_trackers;userid=root;password=mypassword;persistsecurity info=True"
Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT * From Employees", conn)
Dim cb = New MySqlCommandBuilder(da)
'To update the records in the mysql database
ds.Tables("Employees").Rows(incrementdecrement).Item(1) = txtEmployeeProfile.Text.ToString
ds.Tables("Employees").Rows(incrementdecrement).Item(2) = txtEmployeeName.Text.ToString
da.Update(ds, "Employees")
MsgBox("Data Updated", MsgBoxStyle.OkOnly)
End Sub
However, after I have added a Binding Navigator menu to my form, this update button control no longer works.
Thank you in advance.
-
Sep 3rd, 2018, 01:00 AM
#2
Re: Issuing with updating textbox data in visual studio linked to mysql database
Please use appropriate formatting tags when posting code snippets.
vb.net Code:
Private Sub btnEmployeeUpdateDetails_Click(sender As Object, e As EventArgs) Handles btnEmployeeUpdateDetails.Click If incrementdecrement = -1 Then incrementdecrement = 0 End If Dim conn As New MySqlConnection conn.ConnectionString = "server=localhost;Port=3306;database=winery_trackers;userid=root;password=mypassword;persistsecurityinfo=True" Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT * From Employees", conn) Dim cb = New MySqlCommandBuilder(da) 'To update the records in the mysql database ds.Tables("Employees").Rows(incrementdecrement).Item(1) = txtEmployeeProfile.Text.ToString ds.Tables("Employees").Rows(incrementdecrement).Item(2) = txtEmployeeName.Text.ToString da.Update(ds, "Employees") MsgBox("Data Updated", MsgBoxStyle.OkOnly) End Sub
-
Sep 3rd, 2018, 01:06 AM
#3
Re: Issuing with updating textbox data in visual studio linked to mysql database
 Originally Posted by wire_jp
I have added a Binding Navigator menu to my form, this update button control no longer works.
Please define "no longer works". Have you debugged that code? Have you placed a breakpoint on the first line and then stepped through the code line by line, testing the state at each step? Does the code get executed at all? If it does, exactly where and how does the actual state differ from the expected state?
To be honest, I'm not seeing why you have that code at all. The whole point of binding is that the data is moved back and forth between the data source and the UI automatically. If you enter text into those TextBoxes and they are bound to your BindingSource then that text will be automatically pushed down to the current item in your data source. You just need to make sure that you call EndEdit on the BindingSource to commit any pending changes before saving. Why do you think you need to do any manual moving of data in this case?
-
Sep 12th, 2018, 12:16 PM
#4
Thread Starter
Member
Re: Issuing with updating textbox data in visual studio linked to mysql database
Yes, you are right.I have to use the Save button control. Thanks.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|