Gabriel olayinka

Gabriel olayinka

  • NA
  • 119
  • 4.6k

Error while updating database

Mar 30 2018 12:58 AM
why am i getting this error
 
The parameterized query '(STUD_NAME nvarchar(4000),STUD_ID nvarchar(4000),ca_1nvarchar' expects the parameter 'STUD_NAME', which was not supplied.
 
Here is my code
  1. con.Open();  
  2. try  
  3. {  
  4. CalculateTotal();  
  5. for (int i = 0; i < dgAssessment.Rows.Count; i++)  
  6. {  
  7. string cb = ("update ASSESSMENTS set STUD_NAME=@STUD_NAME ,STUD_ID=@STUD_ID,CA_1=@CA_1,CA_2=@CA_2,CA_3=@CA_3,CA_4=@CA_4,EXAM=@EXAM,TOTAL=@TOTAL,GRADE=@GRADE,SUBJ_POSITION=@SUBJ_POSITION,REMARKS=@REMARKS,NO_OF_LESSONS=@NO_OF_LESSONS,ATTENDANCE=@ATTENDANCE where STUD_ID= '" + dgAssessment.Rows[i].Cells["StudentRef"].Value + "'");  
  8. cmd = new SqlCommand(cb);  
  9. cmd.Connection = con;  
  10. cmd.Parameters.AddWithValue("STUD_NAME", dgAssessment.Rows[i].Cells["Student_Name"].Value);  
  11. cmd.Parameters.AddWithValue("STUD_ID", dgAssessment.Rows[i].Cells["StudentRef"].Value);  
  12. cmd.Parameters.AddWithValue("CA_1", dgAssessment.Rows[i].Cells["ca1"].Value);  
  13. cmd.Parameters.AddWithValue("CA_2", dgAssessment.Rows[i].Cells["CA2"].Value);  
  14. cmd.Parameters.AddWithValue("CA_3", dgAssessment.Rows[i].Cells["CA3"].Value);  
  15. cmd.Parameters.AddWithValue("CA_4", dgAssessment.Rows[i].Cells["CA4"].Value);  
  16. cmd.Parameters.AddWithValue("EXAM", dgAssessment.Rows[i].Cells["EXAM"].Value);  
  17. cmd.Parameters.AddWithValue("TOTAL", dgAssessment.Rows[i].Cells["TOTAL"].Value);  
  18. cmd.Parameters.AddWithValue("GRADE", dgAssessment.Rows[i].Cells["GRADE"].Value);  
  19. cmd.Parameters.AddWithValue("SUBJ_POSITION", dgAssessment.Rows[i].Cells["Position"].Value);  
  20. cmd.Parameters.AddWithValue("NO_OF_LESSONS", dgAssessment.Rows[i].Cells["NoofLessons"].Value);  
  21. cmd.Parameters.AddWithValue("ATTENDANCE", dgAssessment.Rows[i].Cells["Attendance"].Value);  
  22. cmd.Parameters.AddWithValue("REMARKS", dgAssessment.Rows[i].Cells["Remark"].Value);  
  23. cmd.ExecuteNonQuery();  
  24. }//end for  
  25. MessageBox.Show("Record Updated Successfully");  
  26. }  
  27. catch (Exception ex)  
  28. {  
  29. MessageBox.Show(ex.Message, " ERROR MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  30. }  
  31. finally  
  32. {  
  33. con.Close();  
  34. }//end finally  

Answers (2)