bound control problem

  • Thread starter Thread starter Tony Martini
  • Start date Start date
T

Tony Martini

Hello,
Hope this is the right newsgroup.
I am using VB.NET. I have bound controls that bind to a small access
database. Adding and deleting records work fine. When I try to modify a
textbox bound to a date time column by removing the date in the textbox the
update puts the old value back in. It does not throw any exceptions. I need
to be able to put dbnull.value into the column if users are removing the
value entered. The field in the db is not required and I can add a new
record without populating it.
Any help would be appreciated.
 
Tony;
Just to make sure I understand the problem... you do a fill on a datatable
and then bind the controls. The field in question is bound to a text box.
You can clear the text box locally, and move back and forth and it stays
clear, but once you fire DataAdapter.Update, it repopulates with the
original value? If that's the case, it sounds like the update isn't working
correctly. I'm assuming you have the default Refresh DataSet option on if
this is the case and that's how it's getting repopulated? Does the access
back end have a defualt value or a formula? If it's not required, then
AddNew would let you add it, I'm just wondering, if you add new then fire
update, does a value come back?
 
Sorry I did not explain the problem well.
I used the dataform wizard ( which may have been my first mistake :) ) to
create the form. It added the dataadapter.fill statement. There is no
default value, input mask or format in the backend. I can do an AddNew and
it updates the database correctly adding records with and without a date
entered. If I do not populate the field there is no problem. It will allow
me to update existing dates with a different date and updates that
correctly. It seems as if the textbox itself is not allowing a null entry if
I set the CausesValidation to true. If I set CausesValidation to false then
it will allow me to tab off the textbox but when I Update or navigate to
another record and then back then it puts to old value back in. I may be way
off base but it seems that it is trying to put a zero length string in the
column (which would be invalid for a date). I have not changed the Refresh
options in the dataset and will have to look into this.
I hope I have explained it better this time around.
Thanks for your input.
Tony
 
Tony:

Ok, that is a lot different issue. If you use a strongly typed dataset for
instance, and you try to put a non-conforming value in it, it will let you
leave the control but it will just switch it back to the original value b/c
it won't let you put in a value that's not legit. Check the column through
code and see if AllowNull is set to true or false. I don't use the Wizard,
but it may be doing this behind the scenes...0 isn't a valid date so it
won't let you do that. I also know if you use a DateTimePicker control for
instance, null values defualt to today's date but you can't not have a value
in there. Let me try to create a form with the Wizard and see what I
canfigure out..

Bill
 
Bill,
I have created a new form that is not using the wizard. I have manually
created the connection object, dataadapter ( with the command objects for
insert, update, delete and select). I have manually added the bindingcontext
for the controls I have put on the form. The only AllowNull property I have
found in the MSDN library is for a datagridboolcolumn which does not apply
here. I did find a dataset.tables().Columns().AlowDBNull property and have
made sure it is set to true. When I created the command objects I made sure
that the parameters are added with IsNullable set to true. The new form I
created has the same behavior as the one created with the wizard. I can
display and update the records but when I try to remove a value from a date
field it puts the old value back.
Many Thanks,
Tony
 
I have found a way to accomplish what I wanted with the bound controls. I
have added handlers to the parse and format events for the databindings that
set the cevent.value to dbnull.value if the value is a zero length string. I
also created a FormatedDataGridColumn inherited from datagridextboxcolumn so
I can format and parse the data by overriding the Commit and
GetColumnValueAaRow events. If anyone else was having this problem this
might help.

Tony
 
Back
Top