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);
}
}
答案 0 :(得分:2)
您不能在查询中指定的列名中包含空格。相反,用方括号[colName]:
装饰列update Table1 set [Bus No] = @bus