我如何...如何最好地在Windows窗体应用程序中指出存在“无价值”的情况。在日期字段?

我如何...如何最好地在Windows窗体应用程序中指出存在“无价值”的情况。在日期字段?

问题描述:

Visual Studio -Visual Basic - Windows窗体。

与Sql server(10.50)dbase的ODBC连接。



数据库日期Cloumn

一般设置

- 数据类型=日期。

- 允许Nulls =是。



如何最好地在Windows窗体中指出日期字段中有无价值?



我应该编码清除(设置为空)数据库中的值吗? (如果Possbile)?







我应编码以呈现空值或defauot值为没有价值?



我的尝试:



我在我的窗口上的Datagridview中清除了日期,并将1900-01-01保存到数据库日期cloumn。

不确定这是应用程序,ODBC连接还是提供此服务器的服务器?



另外

Datetimepicker:如果为null,如何在Windows窗体中指出日期字段中有无值。

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.

似乎你正在寻找 DBNull.Value [ ^ ]

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



或:


or:

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





注意: DataBaseValue 是要检查null的变量/字段。



Note: DataBaseValue is a variable/field you want to check for null.


您可以使用DateTimePicker.Checked属性(System.Windows.Forms)| Microsoft Docs [ ^ ]

除此之外,您可能必须从DateTimePicker派生控件并覆盖OnPaint以显示消息或类似内容。应该不难,但我自己不需要这样做。
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.