Help Setting Datetime or Integer text box to null

mmeier

Member
Joined
Jun 25, 2007
Messages
8
Programming Experience
10+
I'm working with SQL server and VB.net (VS 2005). I have a windows form bound to table adaptor. There are times when I need to be able to blank or null 2 textbox controls. One is a Integer and the other is a datetime field. The SQL table and dataset both allow nulls for the fields. I can add records to the table (via the win form) with these fields null. However, I cannot remove either value once they have been populated.

If the user attempts to change either field back to an empty string, the cursor cannot be moved off of that textbox. Other textboxes that are bound to text type fields can be blanked out as expected.

Any ideas or suggestions?

Thanks!
 
Are you binding your data to these controls? If so then you just set the NullValue property of the Binding to an empty string. Then whenever the control contains an empty string the Binding will push a null value to the data source.
 
When I try to change this, I get the following msg... For columns not defined as System.String, the only valid value is (Throw exception).

I attempted this using the dataset designer on one of the problem fields in my table.

I'm still fairly new at this. Did I attempt what you were suggesting?

Thanks
Mike
 
This has nothing to do with the DataSet designer. It's the Binding object whose NullValue property you need to set. The Binding object is what keeps the data in the data source, i.e. the DataTable, and the data in the control, i.e. the TextBox, in sync. You either created the Binding in the design window for the form in the TextBox's DataBindings property or else you created it in code by calling the DataBindings.Add method of the TextBox.
 
Back
Top