Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Visual Studio -Visual Basic - Windows Form.
ODBC connection to Sql server(10.50) dbase.

Database date Cloumn
General settings
- Data type = date.
- Allow Nulls = Yes.

How best to indicate in the Windows Form that there is "No value" in the date field?

Should i code to clear( set to null ) the value in the database? (if Possbile)?

or

Should i code to present an Null value or defauot value as "No value" ?

What I have tried:

I have cleared dates in a Datagridview on my windows from and "1900-01-01" is saved to the database date cloumn.
Not sure if this is the App, ODBC conenction or the Server providing this ?

Also
Datetimepicker : if null , How best to indicate in the Windows Form that there is "No value" in the date field.
Posted
Updated 10-Apr-19 20:10pm
v2

Seems you're looking for DBNull.Value[^]
VB
If DbNUll.Value.Equals(DataBaseValue) Then
    'set default value
End If

or:
VB
DataBaseValue = IIf(Not DbNUll.Value.Equals(DataBaseValue), DataBaseValue, New DateTime(1900, 1, 1))


Note: DataBaseValue is a variable/field you want to check for null.
 
Share this answer
 
You could use the DateTimePicker.Checked Property (System.Windows.Forms) | Microsoft Docs[^]
Other than that, you'd probably have to derive a control from the DateTimePicker and override OnPaint to display a message or similar. Shouldn't be difficult, but I haven't needed to do it myself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900