那是我的代码并运行此程序,我收到错误消息“ 更新语句中的语法错误

本文关键字:错误 消息 更新 语句 语法 代码 我的 运行 程序 | 更新日期: 2023-09-27 17:56:21

private void btnedit_Click(object sender, EventArgs e)
{
    try
    {
        connection.Open();
        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        string query ="update Table1 set Bus No = @bus, [Route No] = @rno, [Arrested Date] = @ard, [Relevant Office]= @roff, [Temporary Permit No]= @tpno, [Fines No]= @fino, [Arrested Documents]= @arrdo, [Fine Amount]= @famount, [Receipt No]= @reno, [Released Date]= @redate where ID= @id )";
        command.Parameters.AddWithValue("@bus", txt1.Text);
        command.Parameters.AddWithValue("@rno", txt2.Text);
        command.Parameters.AddWithValue("@ard", txt3.Text);
        command.Parameters.AddWithValue("@roff", txt4.Text);
        command.Parameters.AddWithValue("@tpno", txt5.Text);
        command.Parameters.AddWithValue("@fino", txt6.Text);
        command.Parameters.AddWithValue("@arrdo", txt7.Text);
        command.Parameters.AddWithValue("@famount", txt8.Text);
        command.Parameters.AddWithValue("@reno", txt9.Text);
        command.Parameters.AddWithValue("@redate", txt10.Text);
        command.Parameters.AddWithValue("@id", txtid.Text);
        MessageBox.Show(query);
        command.CommandText =query;
        command.ExecuteNonQuery();
        MessageBox.Show("Data Edit Succesful");
        connection.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error " + ex);
    }
}

那是我的代码并运行此程序,我收到错误消息“ 更新语句中的语法错误

查询中指定的列名中不能有空格。相反,使用方括号 [colName] 修饰列:

update Table1 set [Bus No] = @bus