【发布时间】:2015-05-02 15:44:55
【问题描述】:
string str,a;
DateTime dat, aa;
using (con = new SqlConnection(@"Data Source=daniyal\sqlexpress;Initial Catalog=webassign;Integrated Security=True"))
{
con.Open();
using(com = new SqlCommand("select * from tasks",con))
{
rdr = com.ExecuteReader();
while (rdr.Read())
{
str = rdr.GetValue(1).ToString();
dat = DateTime.ParseExact(str, "dd/MM/yyyy", CultureInfo.InvariantCulture);
}
}
}
我想将 varchar 变量解析为保存在我的 SQL Server 中的日期时间
【问题讨论】:
-
你解析的是s而不是str,是不是打错字了?无论如何,您解析的字符串的确切值是多少?
-
请发布您的数据如何存储在 Sql Server 中的示例,例如2014 年 12 月 5 日?
-
可能是日期格式不匹配,或者SQL中的值为空。
-
dd/MM/yyy应该是dd/MM/yyyy
标签: c# asp.net sql-server-2012 datetime-format