将当前日期设置为数据集中的默认值? [英] Set Current Date at default value in a data set?
本文介绍了将当前日期设置为数据集中的默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据集,我试图将默认值设置为当前日期和时间。我认为价值需要是一个字面意思。有没有办法做到这一点?因为我不能使用System.DateTime这样做它似乎。任何建议将是一个很大的帮助。
I have a dataset that i am trying to set the default value as the current date and time. I believe that value needs to be a literal. Is there a certain way to do this? Because I am not able to do this using System.DateTime it seems.Any advice would be a great deal of help.
推荐答案
您可以将相关列的默认值设置为
You can set the default value of relevant column as
dataTable1.Columns["dateTimeColumn"].DefaultValue = System.DateTime.Now;
如果从SQL Server数据库中获取数据,则可以使用 GETDATE
函数:
If you fetch data from a SQL Server database, then you can set the default value using the GETDATE
function:
ALTER TABLE MyTable
ADD CONSTRAINT DF_MyTable_MyColumn
DEFAULT GETDATE() FOR MyColumn
使用以下代码:
UploadHistory.Columns["FileUploadDate"].DefaultValue = System.DateTime.Now;
当表格写成 XML
:
<xs:element name="FileUploadDate"
type="xs:dateTime"
default="2017-03-13T11:39:26.7980069-05:00"
minOccurs="0" />
这篇关于将当前日期设置为数据集中的默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文