2012-04-09 40 views
1

值插入到另一個數據庫中我試圖插入來自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。

回答

1

更換以下

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