简体   繁体   English

SQL从表语法删除行错误

[英]SQL Delete row from table syntax error

removebutton_Click removebutton_Click

protected void removebutton_Click(object sender, EventArgs e)
{
    string RemoveSQL;

    OleDbConnection mDB = new OleDbConnection();
    mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
                           + Server.MapPath("~/App_Data/database.accdb");
    mDB.Open(); OleDbCommand cmd;

    Button removebutton = (Button)sender;
    Label carttransactionlabel = (Label)removebutton.Parent.FindControl("carttransactionlabel");

    int intTransNo = int.Parse(carttransactionlabel.Text);

    RemoveSQL = "DELETE FROM orderItems"
                + "WHERE iTransaction_No = @TransNo";

    cmd = new OleDbCommand(RemoveSQL, mDB);

    cmd.Parameters.Add("@TransNo", OleDbType.Integer).Value = intTransNo;

    cmd.ExecuteNonQuery();

    mDB.Close();
}

What I am trying to accomplish here is that when the user clicks on the removebutton button, the SQL command RemoveSQL will remove the entire row of transaction from the orderItems table in MS Access based on the transaction number ( carttransactionlabel ). 我要在这里完成的工作是,当用户单击removebutton按钮时,SQL命令RemoveSQL将基于事务号( carttransactionlabel )从MS Access的orderItems表中删除整个事务行。

Table enter image description here 表格在这里输入图片说明

However, when I try to click on the removebutton button, this error appears enter image description here 但是,当我尝试单击removebutton按钮时,出现此错误,请在此处输入图像说明

Apparently there's a syntax error in the SQL statement which I can't seem to spot. 显然,SQL语句中存在语法错误,我似乎无法发现。 Help would be appreciated. 帮助将不胜感激。

Print out your SQL before running it! 在运行之前打印出您的SQL! At least some problems will be obvious. 至少有些问题是显而易见的。

You have this code: 您有以下代码:

RemoveSQL = "DELETE FROM orderItems" + "WHERE iTransaction_No = @TransNo";

If you print this out, it will look like: 如果将其打印出来,它将看起来像:

RemoveSQL = "DELETE FROM orderItemsWHERE iTransaction_No = @TransNo";

The error and fix should be obvious. 错误和修复应该很明显。

Note: You may have other issues in your code. 注意:您的代码中可能还有其他问题。

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

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