need help with datatable.defaultview.addnew

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi all,

here's the situation... i have a form and a number of textboxes.
this form only allows single record transaction meaning it can only edit, delete and insert 1 record at a time since it only displays 1 record at a time.

i have already set my adapter's insertcommand, updatecommand and deletecommand.

the deletecommand and updatecommand works perfectly well. the problem i'm having is with the insertcommand... based on further research and studying, my insertcommand does not have any syntax errors because if i bind my datatable to a datagrid and use the insertcommand, it works ok.

anyways, i get a concurrency error when i use the insertcommand.

here's how the form works...

at form_load, i bind my textboxes to my datatable. i have a first, previous, next and last record buttons which allows me to navigate to my datatable. it works ok. i also have a save, delete, add button...

here's how the save and delete button works...

when i delete a record by pressing the delete button, it wont delete the record from my database but it will delete it from my datatable... to delete the record completely i click on the save button which has the adapter.Update(datatable) code... same goes when i edit a field, i need to press save for changes to take effect of course.

now for the add button i have the datatable.defaultview.addnew .., when i press the add button, i also place codes that will clear the fields of their text coz somehow it doesnt do it automatically. then i will try to enter data that is supposed to be considered as a new record... then i press save... thats when i get the concurrency error.

from what i understand, what happens is when i clear the text of the textboxes and then enter new data, i am changing data in the current row index which the datatable thinks i am editing the current record. and since i am also changing the value of the primary key, it causes the concurrency error.

my question is how can i make this datatable.defaultview.addnew work.? i've been trying to find a way to go the row index of the newly created record made by this datatable.defaultview.addnew code. using the datatable.defaultview.position doesnt seem to work.

can anyone help? thanks.
 
when i delete a record by pressing the delete button, it wont delete the record from my database but it will delete it from my datatable... to delete the record completely i click on the save button which has the adapter.Update(datatable) code... same goes when i edit a field, i need to press save for changes to take effect of course.
This is the intended behaviour of a disconnected data architecture

now for the add button i have the datatable.defaultview.addnew
I dont know exactly how this is done in 1.1 but I suspect you would be better off calling the .AddNew() of the CurrencyManager object that is supporting the bindings of the grid.
For more information, please read the DW1 link in my signature, whatever sections seem appropriate

my question is how can i make this datatable.defaultview.addnew work.? i've been trying to find a way to go the row index of the newly created record made by this datatable.defaultview.addnew code. using the datatable.defaultview.position doesnt seem to work.

can anyone help? thanks.

In 2.0, we use the BindingSource which is a lot like CurrencyManager. Calling AddNew on the BS adds a new record to the bindingsource list and makes it the current row. Calling EndEdit on the BS sends this new row into the datatable. CurrencyManager may work the same way, but DW1 will tell you for certain, I dont really know, sorry..
 
ok thanks... im gonna try to study that currencymanager object and see if its gonna work.
 
Last edited:
hey, currencymanager worked... although there are a few bugs regarding databindings with controls like checkboxes binded to their value property.

like for example, i have a GroupBox with 2 radio buttons in it. 1 for Male and 1 for Female. then i bind my column like this... groupbox.databindings.add("tag", datatable, "sex").

im still trying to figure out a way to bypass this problem... i know i can use combobox for this but it doesnt seem good to use combobox if u only have 2 options... so i want to stick with the radiobuttons as much as i can with this column.

if you have any more suggestions, i would gladly hear it.

thanks.
 
hey, currencymanager worked... although there are a few bugs regarding databindings with controls like checkboxes binded to their value property.
Make sure youre binding the checkbox to a data property that is boolean!

like for example, i have a GroupBox with 2 radio buttons in it.
WHoa, hangon - you know that radio buttons and checkboxes are different things, right?

1 for Male and 1 for Female. then i bind my column like this... groupbox.databindings.add("tag", datatable, "sex").
Radiobuttons cannot be bound. Its an often talked about problem. See several web discussions on the issue. I actually use combos for Male/Female because they support binding, even though there are only 2 options


im still trying to figure out a way to bypass this problem...
See the many discussions found by googling "radiobutton binding"

if you have any more suggestions, i would gladly hear it.

thanks.
Some people make a custom control, i just use combo, because the real pro users can use keyboard nav (M key for Male, F for female) and other noob users are happy to click click with the mouse
 
i did some searching regarding radio buttons binding as per your advice... most people do use custom control in this case... i'm not sure if i wanna do that... i just might use combo box instead to simplify things.

also, regarding the checkbox control... unfortunately the database i'm using does not have a boolean data type... so i used number instead... True = 1 and False = 0... the weird thing is that it works on a checkbox in a form but not when on a datagrid... don't know whats causing that but that's a different topic... i'm just gonna open another thread for that.. anyway, thanks so much for your help... you've been very helpful.
 
Back
Top