Board index » delphi » Database not in edit or insert mode

Database not in edit or insert mode

Hi all.

I'm a newbie to the combination Delphi+databases, and I've come across
an annoying little problem in a small database application I'm
building. The aim of the application is to process student's
assessments of courses and lecturers and to provide feedback to
faculty members. I have three tables

1) Lecturers (with fields LCode (key), LName)
2) Courses (fields CCode (key), CName)
3) Main - the key is an autoincrement field; other fields include
Year, Course, Lecturer, Tutor and fields containing the student's
assessment of the course. There are 42 fields in all. Course is
restricted to the values given in CCode in Courses, while Lecturer and
Tutor are restricted to values given in LCode in Lecturers (all
lecturers may function as tutors in their own course or that of
another lecturer, although some courses do not have a tutor). A course
has one lecturer and, possibly, one tutor. Each record contains ONE
student's assessment of ONE course for ONE year. The data is collected
by anonymous questionnaire and no information on the student is
available.

The application has (at present) one form containing a PageControl
with 4 TabSheets. The 4th TabSheet contains 4 DBEdits and 2
DBNavigators which allow input etc to the Lecturers and Courses
tables. The input fields for the Main table are spread over the first
3 TabSheets. Most are DbEdits, but there are 3 TDBLookUpComboBoxes,
the first (Course) linked to the CCode field in Courses and the other
two (Lecturer and Tutor) linked to the LCode field in Lecturers. The
field for the autoincrement field is visible on the form, but does not
accept user input. Finally, there is a DBNavigator linked to the
DataSource for the Main table. When the application is started up,
everything seems fine. I can enter data in the Lecturers and Courses
tables and step quite happily through the tables in browse mode using
the navigator. However, when I attempt to move to another record in
the Main table while in Browse mode, I get the message 'Database not
in edit or insert mode'. After clearing the message, the table does in
fact go to the appropriate record. Anyone have any suggestions as to
why this problem arises? I've tried various things such as replacing
the autoincrement field with a simple DBEdit, replacing the Lookups
with DBEdits, added and removed explicit Referential Integrity
constraints but nothing seems to help. Presumably, I've missed
something very simple(?).

Comments and suggestions are most welcome. Hopefully, I've supplied
sufficient, but not superfluous, information.

Thanks in advance

Joseph

 

Re:Database not in edit or insert mode


Joseph,

  This tends to bite me on the backside from time to time. For me, it
happens when I have an event fire and attempt to assign a value to a
database field while the table is in the Browse state.
Something like :

Procedure Mainform.Field1OnExit(Sender:Object);
Begin
  Table1.FieldByName('FieldA').AsString := 'Something/Anything';
End;

If the above fires when the table is in Browse state, an exception will
fire with the error 'Database not in edit or insert mode'. I usually do
one of the following...

Procedure Mainform.Field1OnExit(Sender:Object);
Begin
  If  Table1.State in [dsInsert,dsEdit] Then
    Table1.FieldByName('FieldA').AsString := 'Something/Anything';
End;

or

Procedure Mainform.Field1OnExit(Sender:Object);
Begin
  If  NOT (Table1.State in [dsInsert,dsEdit]) Then
    Table1.Edit;
  Table1.FieldByName('FieldA').AsString := 'Something/Anything';
End;

Whatever is appropriate.

HTH

Jay

Quote
Joseph McDonnell wrote:
> Hi all.

> I'm a newbie to the combination Delphi+databases, and I've come across
> an annoying little problem in a small database application I'm
> building. The aim of the application is to process student's
> assessments of courses and lecturers and to provide feedback to
> faculty members. I have three tables

> 1) Lecturers (with fields LCode (key), LName)
> 2) Courses (fields CCode (key), CName)
> 3) Main - the key is an autoincrement field; other fields include
> Year, Course, Lecturer, Tutor and fields containing the student's
> assessment of the course. There are 42 fields in all. Course is
> restricted to the values given in CCode in Courses, while Lecturer and
> Tutor are restricted to values given in LCode in Lecturers (all
> lecturers may function as tutors in their own course or that of
> another lecturer, although some courses do not have a tutor). A course
> has one lecturer and, possibly, one tutor. Each record contains ONE
> student's assessment of ONE course for ONE year. The data is collected
> by anonymous questionnaire and no information on the student is
> available.

> The application has (at present) one form containing a PageControl
> with 4 TabSheets. The 4th TabSheet contains 4 DBEdits and 2
> DBNavigators which allow input etc to the Lecturers and Courses
> tables. The input fields for the Main table are spread over the first
> 3 TabSheets. Most are DbEdits, but there are 3 TDBLookUpComboBoxes,
> the first (Course) linked to the CCode field in Courses and the other
> two (Lecturer and Tutor) linked to the LCode field in Lecturers. The
> field for the autoincrement field is visible on the form, but does not
> accept user input. Finally, there is a DBNavigator linked to the
> DataSource for the Main table. When the application is started up,
> everything seems fine. I can enter data in the Lecturers and Courses
> tables and step quite happily through the tables in browse mode using
> the navigator. However, when I attempt to move to another record in
> the Main table while in Browse mode, I get the message 'Database not
> in edit or insert mode'. After clearing the message, the table does in
> fact go to the appropriate record. Anyone have any suggestions as to
> why this problem arises? I've tried various things such as replacing
> the autoincrement field with a simple DBEdit, replacing the Lookups
> with DBEdits, added and removed explicit Referential Integrity
> constraints but nothing seems to help. Presumably, I've missed
> something very simple(?).

> Comments and suggestions are most welcome. Hopefully, I've supplied
> sufficient, but not superfluous, information.

> Thanks in advance

> Joseph

Other Threads