Results 1 to 4 of 4

Thread: [RESOLVED] Issuing with updating textbox data in visual studio linked to mysql database

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2018
    Posts
    46

    Resolved [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    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:
    1. Private Sub btnEmployeeUpdateDetails_Click(sender As Object, e As EventArgs) Handles btnEmployeeUpdateDetails.Click
    2.  
    3.         If incrementdecrement = -1 Then
    4.             incrementdecrement = 0
    5.         End If
    6.  
    7.         Dim conn As New MySqlConnection
    8.         conn.ConnectionString =
    9.        "server=localhost;Port=3306;database=winery_trackers;userid=root;password=mypassword;persistsecurityinfo=True"
    10.         Dim da As MySqlDataAdapter = New MySqlDataAdapter("SELECT * From Employees", conn)
    11.         Dim cb = New MySqlCommandBuilder(da)
    12.  
    13.  
    14.         'To update the records in the mysql database
    15.         ds.Tables("Employees").Rows(incrementdecrement).Item(1) = txtEmployeeProfile.Text.ToString
    16.         ds.Tables("Employees").Rows(incrementdecrement).Item(2) = txtEmployeeName.Text.ToString
    17.         da.Update(ds, "Employees")
    18.  
    19.         MsgBox("Data Updated", MsgBoxStyle.OkOnly)
    20.     End Sub

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Issuing with updating textbox data in visual studio linked to mysql database

    Quote Originally Posted by wire_jp View Post
    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?

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2018
    Posts
    46

    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
  •  



Click Here to Expand Forum to Full Width