简体   繁体   English

VB.net-如何删除Access数据库中的项目?

[英]VB.net - How can I delete an Item in an Access Database?

I'm trying to delete an Item in my Access Database with vb.net 我正在尝试使用vb.net删除Access数据库中的项目

my code is: 我的代码是:

    Dim DString As String = "DELETE * FROM studentTable WHERE ID='" & DataGridView1.SelectedRows.Item(0).Cells(0).Value & "'"
    Dim DCMD As New OleDbCommand(DString, con)
    DCMD.ExecuteNonQuery()
    Fill()

the code is working fine, my Problem is it's not working because my "ID" Row is set to AutoIncrement. 该代码运行正常,我的问题是它不起作用,因为我的“ ID”行设置为AutoIncrement。 What can I do to fix?? 我该怎么解决?

King regards 国王的问候

You have a syntax error in your SQL. 您的SQL中有语法错误。 You do not need a projection (column list) for a DELETE statement. 您不需要DELETE语句的投影(列列表)。

Try removing the * such as: 尝试删除*,例如:

DELETE FROM studentTable WHERE ID=....

Also you do not need to quote numeric values with the apostrophe character (I don't think it will hurt). 同样,您也不需要用撇号将数字值引起来(我认为这不会造成伤害)。

You might also want to consider using a parameterized query instead of embedding the value. 您可能还需要考虑使用参数化查询,而不是嵌入值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM