在 vb.net 中,下面的代码有效
cmd.CommandText = "CREATE TABLE Notes ( num INTEGER, name TEXT)"
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error during save operation: " & ex.Message)
End Try
cmd.CommandText = "insert into Notes(num , name ) VALUES( 3, 'Bob') "
Try
Console.WriteLine(cmd.ExecuteNonQuery())
Catch ex As Exception
MsgBox("Error during save operation: " & ex.Message)
End Try
但我想放置一个整数变量而不是插入数字 3。我试过这个:
Dim count As Integer = 1
cmd.CommandText = "insert into Notes(num , name ) VALUES(" + count " + , 'Bob') "
Try
Console.WriteLine(cmd.ExecuteNonQuery())
Catch ex As Exception
MsgBox("Error during save operation: " & ex.Message)
End Try
但后来我有一个例外:
Conversion from string "insert into Notes(isFirst" to type 'Double' is not valid.
我知道这条线:
"insert into Notes(num , name ) VALUES(" + count + ", 'Bob') "
似乎完全错误,但我找不到任何其他解决方案,因为我都尝试了。
如何将计数变量插入表中?
提前致谢。