且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows窗体中的datetimetoshort问题

更新时间:2023-12-06 12:42:10

重新阅读时,请检查日期是否为空值.如果为null,则将tmpStrDate(定义为字符串)设置为null,否则将日期放在此字段中.使用该字符串值来输入您的数据集.例如

When you read it back in, examine the date for a null value. If it is null set a tmpStrDate (defined as a string) to null, otherwise put the date in this field. Use that string value to feed into your datatset. e.g.

	if (reader->IsDBNull(4) == false)
	{
	    tmp_strValidTo = reader->GetDateTime(4).ToShortDateString();
        }
	else
	{	
	   tmp_strValidTo = nullptr;
	}
<pre>


您正在使用哪个版本的SQL?
which version of SQL you are using?


以正常的DateTime格式将日期保存到数据库中.并绑定到DataGridView列时(或根据需要)转换为Date.ToShortString().
Save date to database in normal DateTime format. And convert to Date.ToShortString() while binding to DataGridView column (or as you needed).