Data binding and Null Values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When you bind a text box to a field that contains null values the text box
displays an empty string. Great!

My Database field is an integer and I want an empty text box to represent a
NULL value. However the EndEdit event on the datarow returns the error The
input string was in an incorrect format

I have failed to find a way to either trap the empty string in the
rowchanging event and turn it into DBNULL or to programatically manipulate
the value in the field to DBNull.Value when a keypress results in no thext
left in the Textbox.

How? Please, can I comunicate a NULL value back to the datarow with a
databound text box?

Regards

Ben Reese
 
Handle the Parse event of the Binding on your textbox. In it, you can return
dbnull.value if the textbox contains an empty string.
 
Back
Top