2013-02-18 67 views
1

在單元格中輸入值,我想下面的代碼在一個單元格中輸入值,以獲得從數據表中的值。但是我得到一個錯誤。以下是錯誤:錯誤通過數據表中的datagridview

The following exception occurred in the DataGridView: System.Exception: 0.91 is not a valid value for Int32. --->

我沒有想法如何消除此錯誤。需要幫忙。

編輯: -

private void DataGrid_CellEnter(object sender, DataGridViewCellEventArgs e) 
    {if (DataGrid.CurrentCell.ColumnIndex == 6) 
      { 
       string getprice = "SELECT " + DataGrid.SelectedRows[0].Cells[3].Value.ToString() + " FROM " + 
        "" + DataGrid.SelectedRows[0].Cells[2].Value.ToString() + "_Mstr " + 
        "WHERE Size1 = '" + DataGrid.SelectedRows[0].Cells[4].Value.ToString() + "'"; 
       DataTable dt = globalData.q.select(getprice); 
       double check; 
       if (double.TryParse(dt.Rows[0][0].ToString(), out check)) 
       { 
        DataGrid.SelectedRows[0].Cells[6].Value = dt.Rows[0][0].ToString().Trim(); 
       } 
      } 
     } 
+2

而你的代碼是..?請閱讀[faq]和[ask] – 2013-02-18 11:40:31

+0

'Size1'的數據類型是什麼? – wizzardz 2013-02-18 11:47:33

+0

編輯了這個問題。 @wizzardz:Size1是'文字'。 – DhavalR 2013-02-18 11:48:08

回答

0

也許當你想到一個int您的SQL是一個雙。 要麼更改數據類型或強制轉換(即具有Convert.ToInt32代替double.Parse(XXX))

+0

我試圖convert.ToInt32(xxx)。但是它提高了價值。價值是雙倍,我期望雙倍。該數據庫是MS Access 2007中 – DhavalR 2013-02-18 12:05:29

+0

恐怕你需要提供更多的信息(即堆棧跟蹤和GridView標記) – 2013-02-18 12:16:34

+0

錯誤的其餘部分是:System.FormatException:輸入字符串的不正確的格式。 在System.Number.StringToNumber(字符串str的NumberStyles選項, NumberBuffer和數量,信息的NumberFormatInfo,布爾parseDecimal) 在System.Number.ParseInt32(字符串s的NumberStyles風格, 的NumberFormatInfo信息) 在System.ComponentModelInt32Converter.FromString(字符串值, 的NumberFormatInfo formatInfo) 在System.ComponentMcdel.BaseNumberConverter.ConvertFrom(ITypeD escriptorContext背景下,Culturelnfo文化,對象的值) – DhavalR 2013-02-18 12:22:45