无法使用参数化插入进行处理

时间:2014-10-28 03:19:50

标签: mysql vb.net

我得到了异常,列不能为空,没有保存到我的数据库。

Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
    con.close()
    con.open()
    cmd = New Odbc.OdbcCommand("INSERT INTO db.table(firstname,lastname) VALUES(@f1,@f2)", con)
    cmd.Parameters.AddWithValue("@f1", textboxfirstname.Text)
    cmd.Parameters.AddWithValue("@f2", textboxlastname.Text)
    cmd.ExecuteNonQuery()
End Sub

但如果我将使用此代码

   Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
    con.close()
    con.open()
    cmd = New Odbc.OdbcCommand("INSERT INTO db.table(firstname) VALUES('" & textboxfirstname.Text & "')", con)   

    cmd.ExecuteNonQuery()
End Sub

0 个答案:

没有答案