问题描述
当保存到DataRow中时,DateTime类的Kind属性始终设置为DateTimeKind.Unspecified。这是正确的行为吗?有没有办法解决这个问题,那么Kind属性的值将被保留?
以下代码的输出是:
Utc
未指定
DataTable table = new DataTable(" Test");
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType(" System。 DateTime");
column.ColumnName =" testdatetime" ;;
table.Columns.Add(column);
DataRow row;
row = table.NewRow();
DateTime value = DateTime.UtcNow;
row [" testdatetime"] = value;
Console.WriteLine(value.Kind);
Console.WriteLine(((DateTime)row [" ; testdatetime"])。Kind);
the Kind property of the DateTime classes always gets set to DateTimeKind.Unspecified when
saved into a DataRow. Is this correct behavior? is there a way to work a around this so
the value of the Kind property will be retained?
the output from the following code is:
Utc
Unspecified
DataTable table = new DataTable("Test");
DataColumn column = new DataColumn();
column.DataType = System.Type.GetType("System.DateTime");
column.ColumnName = "testdatetime";
table.Columns.Add(column);
DataRow row;
row = table.NewRow();
DateTime value = DateTime.UtcNow;
row["testdatetime"] = value;
Console.WriteLine(value.Kind);
Console.WriteLine(((DateTime)row["testdatetime"]).Kind);
这篇关于DateTime.Kind和DataRow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!