的GridView:无法从gridview的

问题描述:

值插入到另一个数据库中我试图插入来自GridView的值到一个数据库,但我得到的错误: 这里是我的设计:http://pastebin.com/vEm3ciPU的GridView:无法从gridview的

我越来越

"Conversion failed when converting date and/or time from character string." "Line 32: dataCommand.ExecuteNonQuery();"

我该怎么办? 谢谢, 我正在使用gridview和sqldatasource绑定datatable到gridview。

更换以下

dataCommand.Parameters.AddWithValue("Name", e.OldValues[0]); 
dataCommand.Parameters.AddWithValue("Value", e.OldValues[2]); 
dataCommand.Parameters.AddWithValue("Total", e.OldValues[3]); 
dataCommand.Parameters.AddWithValue("Date", e.OldValues[4]); 

With Following

dataCommand.Parameters.AddWithValue("Name", e.OldValues[0]); 
dataCommand.Parameters.AddWithValue("Value", e.OldValues[1]); 
dataCommand.Parameters.AddWithValue("Total", e.OldValues[2]); 
DateTime dt; 
if (DateTime.TryParse(e.OldValues[3].ToString(), out dt)) 
    dataCommand.Parameters.AddWithValue("Date", dt); 
else 
    dataCommand.Parameters.AddWithValue("Date", DateTime.Now); 

我假定下面提到的模式。

enter image description here

+0

错误在这里:。DateTime.TryParse(e.OldValues [4],出DT不能从对象转换为字符串 – 2012-04-09 15:38:16

+0

对不起忘了类型转换 – Pankaj 2012-04-09 15:39:27

+0

服务器错误 '/' 应用 指数 参数名称索引 – 2012-04-09 15:40:05