我得到了"System.FormatException:输入的格式错误“。在第二次尝试时出错,而第一次完全正常。
有没有人明白为什么会这样?
尝试1:
Using nCmdIns1 As SQLite.SQLiteCommand = cnUser.CreateCommand
With nCmdIns1
.CommandText = "INSERT INTO images (oemimageguid,imagetitle,imagecategory,imagesize,imageblob256) VALUES (@1,@2,@3,@4,@5)"
.Parameters.Add("@1", DbType.String).Value = uOEMImageGUID
.Parameters.Add("@2", DbType.String).Value = uTitle
.Parameters.Add("@3", DbType.Int32).Value = iCat
.Parameters.Add("@4", DbType.Int32).Value = uImageSize
.Parameters.Add("@5", DbType.Binary).Value = uBytes
.ExecuteNonQuery()
End With
End Using尝试2:
Using nCmdIns2 As SQLite.SQLiteCommand = cnUser.CreateCommand
With nCmdIns2
.CommandText = "INSERT INTO images (oemimageguid,imagetitle,imagecategory,imagesize,imageblob256) VALUES (@1,@2,@3,@4,@5)"
.Parameters.AddWithValue("@1", DbType.String).Value = uOEMImageGUID
.Parameters.AddWithValue("@2", DbType.String).Value = uTitle
.Parameters.AddWithValue("@3", DbType.Int32).Value = iCat
.Parameters.AddWithValue("@4", DbType.Int32).Value = uImageSize
.Parameters.AddWithValue("@5", DbType.Binary).Value = uBytes
.ExecuteNonQuery()
End With
End Using我试图通过一个接一个地删除参数和值来隔离问题,但最后,即使使用这条稀疏线,我也得到了相同的错误:
Using nCmdIns3 As SQLite.SQLiteCommand = cnUser.CreateCommand
With nCmdIns3
.CommandText = "INSERT INTO images (oemimageguid) VALUES (@1)"
.Parameters.AddWithValue("@1", DbType.String).Value = uOEMImageGUID
.ExecuteNonQuery()
End With
End Using以下是尝试3的异常屏幕截图:

发布于 2017-08-21 02:24:04
AddWithValue的第二个参数是值本身,而不是类型
请参阅MSDN AddWithValue。
在任何情况下,请始终尝试使用第一种方法,因为您可以更好地控制参数的类型。
Can we stop using AddWithValue already?
Using nCmdIns2 As SQLite.SQLiteCommand = cnUser.CreateCommand
With nCmdIns2
.CommandText = "INSERT INTO images (oemimageguid,imagetitle,imagecategory,imagesize,imageblob256) VALUES (@1,@2,@3,@4,@5)"
.Parameters.AddWithValue("@1", uOEMImageGUID)
.Parameters.AddWithValue("@2", uTitle)
.Parameters.AddWithValue("@3", iCat)
.Parameters.AddWithValue("@4", uImageSize)
.Parameters.AddWithValue("@5", uBytes)
.ExecuteNonQuery()
End With
End Usinghttps://stackoverflow.com/questions/45785446
复制相似问题