如何将日期时间存储到字符串变量 [英] How to store a datetime to a string variable
本文介绍了如何将日期时间存储到字符串变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用以下代码以'dd / MM / yyyy'格式检索变量v_orderdate。
它不接受将错误声明为'无过载方法'To String'需要'1'争论'。
string v_orderdate =(ds1.Tables [0] .Rows [i] [orderdate])。ToString(dd / MM / yyyy);
解决方案
啊。那是因为它不是那个阶段的DateTime
- 它只是一个对象
当它从SQL返回时数据表。首先,将其转换为DateTime:
string v_orderdate =((DateTime)ds1.Tables [ 0 ]。行[i] [ orderdate]).ToString( dd / MM / yyyy);
I tried using the following code to retrieve in 'dd/MM/yyyy' format to a variable v_orderdate.
It is not accepting stating an error as 'No overload method 'To String' takes '1' arguements'.
string v_orderdate =(ds1.Tables[0].Rows[i]["orderdate"]).ToString("dd/MM/yyyy");
解决方案
Ah. That's because it isn't aDateTime
by that stage - it's just anobject
when it's returned from SQL or in a DataTable. So first, cast it to a DateTime:
string v_orderdate =((DateTime) ds1.Tables[0].Rows[i]["orderdate"]).ToString("dd/MM/yyyy");
这篇关于如何将日期时间存储到字符串变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文