我在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”的强制转换无效。]
什么原因造成的,我在数据库中换成字符串类型就行了!换成整型就不行,为什么?
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”的强制转换无效。]
什么原因造成的,我在数据库中换成字符串类型就行了!换成整型就不行,为什么?
strid = mygrid.Items(e.Item.ItemIndex).Cells(0).Text
转换前先判断是否为空