Handling SQL Server Fields with Null Values on VB .Net Windows Forms
Posted on 2004-10-29
I have a SQL Server 2000 database which contains tables with nullable fields. One such field is [Date Complete]. In my code (VB .Net 2003), I bind the field to a textbox control using the code below.
txtDateComplete.DataBindings.Add(New Binding("Text", drProject, "Date_Complete"))
When the application runs, I receive the following error as a result.
Additional information: Property accessor 'Date_Complete' on object 'Project_Tracker.sqldsProject+ProjectRow' threw the following exception:'Cast from type 'DBNull' to type 'Date' is not valid.'
I do not have any formatting attributes applied to the textbox control as that doesn't appear to be an option in the properties window for the control.
Does anyone know how I can get controls on my Windows forms to accept NULL values from fields? Any help would be greatly appreciated. Hopefully this is a simple question for soem of you. I am learning the .Net technology and for me, this issue has been a stumbling block for several days now.