Data binding
-
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
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[^]
-
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[^]
-
Thanks , :) the DataRowState remains "unchanged" do u know what could be the problem in the bindingsource??? :)
Have Fun Never forget it
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[^]
-
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[^]
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
-
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
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 callt_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[^]
-
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 callt_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[^]
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
-
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
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[^]
-
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[^]
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
-
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
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[^]
-
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[^]
-
THANKS :) i'll try it and again thank alot for the help and patience :) :)
Have Fun Never forget it