1

My code:

OleDbCommand cmd1 = new OleDbCommand("UPDATE student_info SET fee_due = @fee_due WHERE adm_no = @adm_no", con);

cmd1.Parameters.AddWithValue("@adm_no", adm_no);
cmd1.Parameters.AddWithValue("@fee_due", fee_due);

int affect = cmd1.ExecuteNonQuery();

MessageBox.Show(affect.ToString());

My code always shows 0 row affected every time but in my database the are must be a row that will be affect

Can you suggest me how I debug this problem?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Prashant
  • 394
  • 1
  • 6
  • 18
  • Try to set the parameters in the correct order of your statement. OleDB is really picky when it gets to parameters. Check this out: http://stackoverflow.com/questions/15126427/oledb-update-command and this: http://stackoverflow.com/questions/30648602/oledb-update-command-not-changing-data – Sebastian Siemens Feb 02 '17 at 16:02

1 Answers1

1

Since OleDB for MS Access doesn't support named parameters (only positional parameters), you must be very careful about providing the values in the same order in which you define the parameters.

In your case, the statement lists @fee_due first, before @adm_no - but you provide the values in the other order.

Change your code like this:

OleDbCommand cmd1 = new OleDbCommand("UPDATE student_info SET fee_due = @fee_due WHERE adm_no = @adm_no", con);

// provide the value for @fee_due FIRST    
cmd1.Parameters.AddWithValue("@fee_due", fee_due);

// provide the value for @adm_no only after @fee_due
cmd1.Parameters.AddWithValue("@adm_no", adm_no);

int affect = cmd1.ExecuteNonQuery();

MessageBox.Show(affect.ToString());
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459