DELETE语句中的SQL语法错误

时间:2015-05-13 11:48:20

标签: vb.net

执行DELETE SQL语句时,我收到错误消息

  

SYNTAX ERROR NEAR'*'

以下代码中的错误是什么?

applicationDidBecomeActive:
applicationWillResignActive:
applicationDidEnterBackground:
applicationWillEnterForeground:
applicationWillTerminate:

1 个答案:

答案 0 :(得分:5)

删除*,它不属于DELETE,而属于SELECT

DELETE FROM pc ...

此外,始终使用sql-parameters来阻止sql注入和Using语句。

Using con As New SqlConnection("Connectino string")
    Using rs As New SqlCommand("DELETE FROM pc WHERE pcname=@pcname", con)
        rs.Parameters.Add("@pcname", SqlDbType.VarChar).Value = Label5.Text.Trim()
        con.Open()
        Dim deleted As Int32 = rs.ExecuteNonQuery()
        If deleted > 0 Then
            MessageBox.Show("Data Deleted")
        End If
    End Using '  connection doesn't need to be closed due to the Using
End Using