问题描述
我有一个带有日期的数据集。类型是Sql Server上的smalldatetime
而我只是做了一个SELECT * from x;得到它。
我所有的其他字段都很好,但是这个字段给我一个错误:
指定演员表是无效的。
回来的数据是:
2005-05-09 17:52:59.923
我的C#行是:
dateCreated =(字符串)user [" DateCreated"];
我也尝试过:
dateCreated =(DateTime)user [" DateCreated"];
我该怎么设置这个以获取我的日期没有兑换成
VarChar?
谢谢,
汤姆
I have a dataset with a date in it. The type is smalldatetime on Sql Server
and I am just doing a "SELECT * from x" to get it.
All my other fields are fine, but this one gives me an error of:
Specified cast is not valid.
The data that is coming back is:
2005-05-09 17:52:59.923
My C# line is:
dateCreated = (string)user["DateCreated"];
I also tried:
dateCreated = (DateTime)user["DateCreated"];
How am I supposed to set this to get a date that I haven''t converted to a
VarChar?
Thanks,
Tom
推荐答案
这是有效的,我将如何在网页上执行此操作页面上的字段。
但是如果我打算在一个对象中携带日期,那么我就可以获得类似x的内容。 DateCreated",最好是把它作为一个
字符串或者作为DateTime吗?
谢谢,
汤姆
That works and is how I would do it on a web page to a field on the page.
But if I am going to carry the date around in an object so that I would
access it something like "x.DateCreated", is it better to carry it as a
string or as DateTime?
Thanks,
Tom
这篇关于来自Sql的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!