我收到此异常时,我的列的数据表中有一个空值。假设我想要允许空值或类似的东西,我该如何解决这个问题?字符串未被识别为有效的日期时间。
字符串未被识别为有效的DateTime。
这是我的代码。
foreach (DataRow row in ds.Tables[0].Rows)
{
row["Effective_Period"] = Convert.ToDateTime(row["Effect_Date_From"].ToString()).ToString("dd/MM/yyyy")
+ " - " + Convert.ToDateTime(row["Effect_Date_To"].ToString()).ToString("dd/MM/yyyy");
}
在我ds.Table,这里是我的专栏
----------------------
Effective_Period
---------------------
10/2/2012 - 20/3/2012
---------------------
---------------------
---------------------
当列有'null'时你想要做什么? –
你不能将空列转换为datatime这就是为什么你会得到错误,我建议你更新你的存储过程来处理空值,以便你不会返回任何空值。 – user2705620
可能的重复http://stackoverflow.com/questions/2193012/string-was-not-recognized-as-a-valid-datetime-format-dd-mm-yyyy –