本文介绍了DateTime.Kind和DataRow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当保存到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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:34