none
AddRow method to existing Dataset RRS feed

  • Question

  • I have a series of Textboxes in my application which are not bound to any Data source.

    To save a new record, I use the Add row method (I tried using the Datatable.Add row method to no avail).

    At the time of saving, this is the code I use:

      Dim NewRow = Me.myDataSet.Color.NewRow()

    And then I proceed to "transfer" the data from my Textboxes to each Data Row Columns this way:

      NewRow("VALUE_X") = textBox_X.Text
      NewRow("VALUE_Y") =
    textbox_Y.Text
      NewRow("VALUE_Z") =
    textbox_Z.Text

    This is followed by a bunch of these kinds of columns:

    NewRow("nm380") = textbox_380.Text
    NewRow("nm390") = textbox_390.Text
    NewRow("nm400") = textbox_400.Text
    ...
    NewRow("nm730") = textbox_730.Text

    There are 32 such "nmXXX" in myDataSet.Color table in all.

    As soon as I issue this instruction Me.myDataSet.Color.Add(NewRow), all bets are off!
    For some "reason" only the TextBoxes with these "nmXXX" column names becomes "0", all of a sudden, in the interface, but not the VALUE_X, Y and Z TextBoxes. Those remain the same. Here is a screen capture which document this behavior :

    In the Dataset, everyone of those columns 'System.Single' and in the SQL Table, everyone of those columns are shown as 'Real'.

    What could I possibly do wrong?

    Tuesday, March 31, 2020 5:02 PM

Answers

  • I must be doing things the hard way, because I insist on doing everything "manually".

    I still have no explanation for why some values turn to zeroes while others don't? But I reasoned that, in order to avoid the user freaking out when the confirmation dialog comes up, I navigate to the "Before Last Record" in the Data Table, which lands at exactly the right place. And all the original values seem to remain intact. Not elegant but it works.

    I ought to investigate using a Binding Navigator as Lester suggested ...

    Thanks everyone for your help and comments.

    • Marked as answer by roger.breton Tuesday, March 31, 2020 5:18 PM
    Tuesday, March 31, 2020 5:18 PM
  • Karen, I had a "hunch". You may remember from my other post, this morning, that those "nmXXX' Textboxes were originally part of a Tab control "Tab Page". When I selected all those 32 Textboxes and their associated labels and "cut" them out of the Tab Page I originally created them in, to later paste them onto the regular area of my WinForm, unknowingly, I might have carried some "souvenir" (the best way I can explain this) from the "days" these Textboxes were "living" in that Tab Page? It's theory and that could explain why the XYZ values that belonged to the other Textboxes "worked as expected" and not those?

    To test my theory, I deleted three of those original 32 Text boxes and recreate them, fresh, out of the Toolbox. Lo and behold, they're now updating correctly!!! See this screen capture:

    All the other Textboxes are "Zeroes". 

    • Marked as answer by roger.breton Tuesday, March 31, 2020 6:06 PM
    Tuesday, March 31, 2020 6:06 PM

All replies

  • I must be doing things the hard way, because I insist on doing everything "manually".

    I still have no explanation for why some values turn to zeroes while others don't? But I reasoned that, in order to avoid the user freaking out when the confirmation dialog comes up, I navigate to the "Before Last Record" in the Data Table, which lands at exactly the right place. And all the original values seem to remain intact. Not elegant but it works.

    I ought to investigate using a Binding Navigator as Lester suggested ...

    Thanks everyone for your help and comments.

    • Marked as answer by roger.breton Tuesday, March 31, 2020 5:18 PM
    Tuesday, March 31, 2020 5:18 PM
  • You should be able to use this syntax where the position of each TextBox matches the ordinal position of the column the data in the TextBox belongs too. 

    Me.myDataSet.Color.Rows.Add(New Object() {textBox_X.Text, ....})

    When not string type convert the Text value then set 

    Dim VALUE_X = CType(textBox_X.Text,Single)

    Me.myDataSet.Color.Rows.Add(New Object() {VALUE_X, ....})


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 31, 2020 5:42 PM
    Moderator
  • Karen, I had a "hunch". You may remember from my other post, this morning, that those "nmXXX' Textboxes were originally part of a Tab control "Tab Page". When I selected all those 32 Textboxes and their associated labels and "cut" them out of the Tab Page I originally created them in, to later paste them onto the regular area of my WinForm, unknowingly, I might have carried some "souvenir" (the best way I can explain this) from the "days" these Textboxes were "living" in that Tab Page? It's theory and that could explain why the XYZ values that belonged to the other Textboxes "worked as expected" and not those?

    To test my theory, I deleted three of those original 32 Text boxes and recreate them, fresh, out of the Toolbox. Lo and behold, they're now updating correctly!!! See this screen capture:

    All the other Textboxes are "Zeroes". 

    • Marked as answer by roger.breton Tuesday, March 31, 2020 6:06 PM
    Tuesday, March 31, 2020 6:06 PM