2016-07-11 5 views
-2
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); 
    } 
} 

答えて

2

クエリで指定された列名にスペースを入れることはできません。代わりに、角括弧[colName ]:

update Table1 set [Bus No] = @bus 
関連する問題