Textbox.databinding.add - Does not write back to Underlying table

  • 9 years ago

    Hi,

    I have a form with a few text boxes. All of them are bound to a table in a SQL database as follows in the Form Load event.


    textbox1.databindings.add(new binding("Text", ds.tables(0), "id")
    textbox2.databindings.add(new binding("Text", ds.tables(0), "Name")

    When the form is loaded, I create a new record into the table with the following code.

    dim dr as datarow
    dr = ds.tables(0).newrow

    dr("id") = 1
    dr("Name") = "Hello"
    ds.tables(0).rows.add(dr)

    The information that I have passed into the datarow (dr) comes visible into the text boxes when the form is displayed....but...if I go and change the word "Hello" to "Hello123" (just for testing purpose)...and press the save button (which runs the update code as below)...I expect the revised "Hello123" to be written back to the table in SQL. But this does not happen...where as the word "Hello" gets written back.

    private sub Save()

    dim dtnew as datatable
    dtnew = ds.tables(0).getchanges(datarowstate.added)

    da.update(dtnew)

    end sub

    Can anyone tell me what I am doing wrong or am I missing something somewhere. Need your assistance desperately.

    Best Rgds
    TempleGate

  • 8 years ago

    Although this is an old post - I think for other readers out there...

    This is line with the issue: dtnew = ds.tables(0).getchanges(datarowstate.added) Specifically - datarowstate.added I think you need to include changed row data - because you added the row in one part, and then changed it in another

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”