Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Data binding

Data binding

Scheduled Pinned Locked Moved C#
databasewpfwcfquestionannouncement
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    half life
    wrote on last edited by
    #1

    Hi, i've bounded a TextBox, DateTimePicker and NumericUpDown to a database Via a BindingSource the thing is that when i change one of the values nothing happens here is the ButtonClickEvent that should Update the DB

        private void button1\_Click(object sender, EventArgs e)
        {
            t\_AppTableAdapter.Update(dataSet2.T\_App.Rows\[0\]);
            dataSet2.AcceptChanges();
        }
    

    where do i go wrong??

    Have Fun Never forget it

    W 1 Reply Last reply
    0
    • H half life

      Hi, i've bounded a TextBox, DateTimePicker and NumericUpDown to a database Via a BindingSource the thing is that when i change one of the values nothing happens here is the ButtonClickEvent that should Update the DB

          private void button1\_Click(object sender, EventArgs e)
          {
              t\_AppTableAdapter.Update(dataSet2.T\_App.Rows\[0\]);
              dataSet2.AcceptChanges();
          }
      

      where do i go wrong??

      Have Fun Never forget it

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      First, set a breakpoint to

      t_AppTableAdapter.Update(dataSet2.T_App.Rows[0]);

      and check the RowStates and that they are Modified. If the RowState isn't set, the problem is most likely in binding. Also the Update method takes a datatable or a datarow array as a parameter. Now you pass only one row. If you want to update all the modifications in the datatable, call:

      t_AppTableAdapter.Update(dataSet2.T_App);

      The need to optimize rises from a bad design.My articles[^]

      H 1 Reply Last reply
      0
      • W Wendelius

        First, set a breakpoint to

        t_AppTableAdapter.Update(dataSet2.T_App.Rows[0]);

        and check the RowStates and that they are Modified. If the RowState isn't set, the problem is most likely in binding. Also the Update method takes a datatable or a datarow array as a parameter. Now you pass only one row. If you want to update all the modifications in the datatable, call:

        t_AppTableAdapter.Update(dataSet2.T_App);

        The need to optimize rises from a bad design.My articles[^]

        H Offline
        H Offline
        half life
        wrote on last edited by
        #3

        Thanks , :) the DataRowState remains "unchanged" do u know what could be the problem in the bindingsource??? :)

        Have Fun Never forget it

        W 1 Reply Last reply
        0
        • H half life

          Thanks , :) the DataRowState remains "unchanged" do u know what could be the problem in the bindingsource??? :)

          Have Fun Never forget it

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          First you could check that just after modifying a value in a control, the datatable contains the change (and the rowstate is Modified). If the modification is not reflected correctly to the datatable, your control binding isn't correctly. If the modification is visible in the datatable, then I would suspect that you call either AcceptChanges or RejectChanges somewhere before you call the DataAdapter.Update. Also it could be possible that you have binded a datatable to the controls, but you are actually trying to save a different datatable (a copy?).

          The need to optimize rises from a bad design.My articles[^]

          H 1 Reply Last reply
          0
          • W Wendelius

            First you could check that just after modifying a value in a control, the datatable contains the change (and the rowstate is Modified). If the modification is not reflected correctly to the datatable, your control binding isn't correctly. If the modification is visible in the datatable, then I would suspect that you call either AcceptChanges or RejectChanges somewhere before you call the DataAdapter.Update. Also it could be possible that you have binded a datatable to the controls, but you are actually trying to save a different datatable (a copy?).

            The need to optimize rises from a bad design.My articles[^]

            H Offline
            H Offline
            half life
            wrote on last edited by
            #5

            Thanks :) but the thing is that the modification is visible, i can see the dataset.table.rows[0].itemarray[0...].values changing before and after i call the update method and the acceptchanges method :( i do not call updatechanges(), certainly not rejectchanges() Before the update method what do u mean by a copy?? of the datatable, i've created it once and been using it all along (via the wizard... Add DataBase...) i think i'm missing somthing maybe in the basics of the concept :( but yet again thanks alot for the help :) :) :)

            Have Fun Never forget it

            W 1 Reply Last reply
            0
            • H half life

              Thanks :) but the thing is that the modification is visible, i can see the dataset.table.rows[0].itemarray[0...].values changing before and after i call the update method and the acceptchanges method :( i do not call updatechanges(), certainly not rejectchanges() Before the update method what do u mean by a copy?? of the datatable, i've created it once and been using it all along (via the wizard... Add DataBase...) i think i'm missing somthing maybe in the basics of the concept :( but yet again thanks alot for the help :) :) :)

              Have Fun Never forget it

              W Offline
              W Offline
              Wendelius
              wrote on last edited by
              #6

              Ok. I'm a bit confused since in your earlier post you said that the rowstate was not modified before calling update? So are these correct observations: - you change the data using a control - immediately after that, your datatable contains a record with RowState = Modified - when you come to the point where you call adapter's Update, your datatable doesn't have a record which is Modified? Also remember that if your datatable contains more than one record, you originally updated only the row at index 0 (t_AppTableAdapter.Update(dataSet2.T_App.Rows[0]);) maybe the record you modified using UI isn't that record. For that reason you should always call t_AppTableAdapter.Update(dataSet2.T_App); When I wrote about the copy, I meant that is it possible that you actually have two different datatables. Changes are made to one datatable but update is called using another. But if you're sure that you have only one datatable, then this won't be an issue.

              The need to optimize rises from a bad design.My articles[^]

              H 1 Reply Last reply
              0
              • W Wendelius

                Ok. I'm a bit confused since in your earlier post you said that the rowstate was not modified before calling update? So are these correct observations: - you change the data using a control - immediately after that, your datatable contains a record with RowState = Modified - when you come to the point where you call adapter's Update, your datatable doesn't have a record which is Modified? Also remember that if your datatable contains more than one record, you originally updated only the row at index 0 (t_AppTableAdapter.Update(dataSet2.T_App.Rows[0]);) maybe the record you modified using UI isn't that record. For that reason you should always call t_AppTableAdapter.Update(dataSet2.T_App); When I wrote about the copy, I meant that is it possible that you actually have two different datatables. Changes are made to one datatable but update is called using another. But if you're sure that you have only one datatable, then this won't be an issue.

                The need to optimize rises from a bad design.My articles[^]

                H Offline
                H Offline
                half life
                wrote on last edited by
                #7

                Here is the symptom step by step 1. i change the value of a textbox bound to column in table (this table has only 1 Row) 2. before i call the adapter's update method i can see that value has been cahnged in the dataset. 3. after i finish the update the rowstate still stays unchanged, only after i call the acceptchanges the rowstate changes but yet no affect on the *.mdb tables the dataset is updated but not the data base itself :(

                Have Fun Never forget it

                W 1 Reply Last reply
                0
                • H half life

                  Here is the symptom step by step 1. i change the value of a textbox bound to column in table (this table has only 1 Row) 2. before i call the adapter's update method i can see that value has been cahnged in the dataset. 3. after i finish the update the rowstate still stays unchanged, only after i call the acceptchanges the rowstate changes but yet no affect on the *.mdb tables the dataset is updated but not the data base itself :(

                  Have Fun Never forget it

                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #8

                  The dataadapter calls AcceptChanges when modifications are done so you don't have to call it. Based on those observations, I would guess that the dataadapter isn't trying to update the record. Two questions: - have you set adapter's UpdateCommand and if so, what's it like or - do you rely on the mechanism that UpdateCommand is automatically generated

                  The need to optimize rises from a bad design.My articles[^]

                  H 1 Reply Last reply
                  0
                  • W Wendelius

                    The dataadapter calls AcceptChanges when modifications are done so you don't have to call it. Based on those observations, I would guess that the dataadapter isn't trying to update the record. Two questions: - have you set adapter's UpdateCommand and if so, what's it like or - do you rely on the mechanism that UpdateCommand is automatically generated

                    The need to optimize rises from a bad design.My articles[^]

                    H Offline
                    H Offline
                    half life
                    wrote on last edited by
                    #9

                    i rely on the mechanism that UpdateCommand is automatically generated, Why? iv'e tried to change it and also checked the query before, using the Execute Query Button and it worked fine until the update method was called in code and this exception came along : "ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value" so i kind'a backed away from the change :) :) and again thanks for the help :)

                    Have Fun Never forget it

                    W 1 Reply Last reply
                    0
                    • H half life

                      i rely on the mechanism that UpdateCommand is automatically generated, Why? iv'e tried to change it and also checked the query before, using the Execute Query Button and it worked fine until the update method was called in code and this exception came along : "ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value" so i kind'a backed away from the change :) :) and again thanks for the help :)

                      Have Fun Never forget it

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #10

                      half-life wrote:

                      i rely on the mechanism that UpdateCommand is automatically generated, Why?

                      In order for this to work, you must have a key column in the datatable and the select command must be created using SqlCommandBuilder or OleDbCommandBuilder. Otherwise it won't work. So you could check that the dataset contains key definition for your datatable.

                      half-life wrote:

                      ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

                      If this is generated by a update command you explicitely supplied, there's propably some mismatch in the columns versus parameter values.

                      The need to optimize rises from a bad design.My articles[^]

                      H 1 Reply Last reply
                      0
                      • W Wendelius

                        half-life wrote:

                        i rely on the mechanism that UpdateCommand is automatically generated, Why?

                        In order for this to work, you must have a key column in the datatable and the select command must be created using SqlCommandBuilder or OleDbCommandBuilder. Otherwise it won't work. So you could check that the dataset contains key definition for your datatable.

                        half-life wrote:

                        ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value

                        If this is generated by a update command you explicitely supplied, there's propably some mismatch in the columns versus parameter values.

                        The need to optimize rises from a bad design.My articles[^]

                        H Offline
                        H Offline
                        half life
                        wrote on last edited by
                        #11

                        THANKS :) i'll try it and again thank alot for the help and patience :) :)

                        Have Fun Never forget it

                        W 1 Reply Last reply
                        0
                        • H half life

                          THANKS :) i'll try it and again thank alot for the help and patience :) :)

                          Have Fun Never forget it

                          W Offline
                          W Offline
                          Wendelius
                          wrote on last edited by
                          #12

                          half-life wrote:

                          i'll try it

                          If you encounter problems, drop a new post.

                          half-life wrote:

                          and again thank alot for the help and patience

                          No problem, glad to help you :)

                          The need to optimize rises from a bad design.My articles[^]

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups