我在access中设置了一个字段id 是integer的,在vb.net中编写程序
   Dim strsql As String
     Dim strid As Integer
    strid = Int(mygrid.Items(e.Item.ItemIndex).Cells(0).Text)
    strsql = "delete from " & Session("table") & " where id=" & strid
    Dim oleconn As New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data       source='" & dsource & "'")
但提示输入字符串的格式不正确!strid = Int(mygrid.Items(e.Item.ItemIndex).Cells(0).Text)这个错误.
[FormatException: 输入字符串的格式不正确。]
[InvalidCastException: 从字符串“”到类型“Double”的强制转换无效。]
什么原因造成的,我在数据库中换成字符串类型就行了!换成整型就不行,为什么?

解决方案 »

  1.   

    Dim strid As String
    strid = mygrid.Items(e.Item.ItemIndex).Cells(0).Text
      

  2.   

    mygrid.Items(e.Item.ItemIndex).Cells(0).Text = ‘’,当然不行了。
      

  3.   

    mygrid.Items(e.Item.ItemIndex).Cells(0).Text为空,而你要把它转换成int型。
    转换前先判断是否为空
      

  4.   

    dim strid = mygrid.Items(e.Item.ItemIndex).Cells(0).Text
      

  5.   

    在你的mygrid.Items(e.Item.ItemIndex).Cells(0).Text没有数据,空串不能转换为int型的,你要判断mygrid.Items(e.Item.ItemIndex).Cells(0).Text的值为不为空在做相应的转换