simon taylor

simon taylor

  • NA
  • 38
  • 69.1k

Updating a record in ms access db where there is a checkbox

Jan 14 2011 9:13 AM

Hi,
i have created  a class called QalificationOnEntry and another class called dataConnection which is used to connect to my ms access db. In my QalificationOnEntry class, one of my data members is of type int called 'check' which is used to insert a value of 1 or 0 into my ms access table called QualificationOnEntry where one of my fields is a checkbox. When i test my QalificationOnEntry class by making an object of this class and setting values for the data members and inserting the data into my ms access table, QualificationOnEntry , i am able to see the record. The problem i am having is trying to update the same record based on an 'entryId' as i get an error saying "Input string was not in a correct format." on this line,
set_checked(
Convert.ToInt32(data[current_index, 7])); // error pointing here
Can somebody tell me why i get this error? The above line of code is the checkbox, but if i can insert a value why can't i update 1 of the columns for this same record?
 
QalificationOnEntry qu = new QalificationOnEntry();
      /*
      * insert statment works fine
      * qu.set_studentId(2);
      qu.set_levelOfQualification("MY LEVEL");
      qu.set_subject("A+ SUBJECT");
      qu.set_examBoard("SOME EXAM BOARD");
      qu.set_grade("FAILE!!!");
      qu.set_dateTaken(d1);
      qu.set_checked(1);
      qu.set_checkedBy("checked by me");
      qu.set_checkedDate(d2);

      qu.insertRecord();*/


      // update same record does not work fine
      qu.loadByEntryId(30);
      MessageBox.Show("subject is " + qu.get_subject());
     
      qu.set_subject("N+ SUBJECT");
      qu.set_checked(1);
      qu.updateRecord(30);


 public void updateRecord(int id)
    {
      dataConnection ds = new dataConnection();
      ds.executeCommand("UPDATE QalificationOnEntry SET entryId='" + entryId + "',studentId=" + "'" + studentId + "'" + ",levelOfQualification=" + "'" + levelOfQualification + "'" + ",subject=" + "'" + subject + "'" + ",examBoard=" + "'" + examBoard + "'" + ",grade=" + "'" + grade + "'" + ",dateTaken=" + "'" + dateTaken + "'" + ",checked=" + "'" + @check + "'" + ",checkedBy=" + "'" + checkedBy + "'" + ",checkedDate=" + "'" + checkedDate + "'" + " WHERE entryId = " + id);
    }


Answers (3)