Hi all,
When I click on the add button I get
"exception class EdatabaseError with message 'DBedit2: Field 'RoomNumber' not found
I am trying to get the max roomnumber to insert a new room max(roomnumber)+1
Its a fundamental hole in my knowledge here, on how to get a result from the database into a pascal variable.
Showroom and update both work as expected.
Table definition
'CREATE TABLE Rooms (roomnumber number, roomname TEXT(100),description memo)';
Procedure TRoomForm.ShowRoom;
begin
adoquery1.close;
adoquery1.SQL.Clear;
ADOQuery1.SQL.Add('Select roomname,description from Rooms where RoomNumber = :p1');
AdoQuery1.Parameters[0].Value:=CurrentRoom;
adoquery1.Open;
adoquery2.close;
adoquery2.SQL.Clear;
ADOQuery2.SQL.Add('Select * from passages where room = :p1');
AdoQuery2.Parameters[0].Value:=CurrentRoom;
adoquery2.Open;
end;
procedure TRoomForm.InitializeClick(Sender: TObject);
begin
initdatabase;
showroom;
end;
procedure TRoomForm.UpdateClick(Sender: TObject);
begin
adocommand1.CommandText := 'update rooms set roomname = :p1, description = :p2 where RoomNumber = :p3';
ADOCommand1.Parameters[0].value := dbedit1.Text;
ADOCommand1.Parameters[1].value := dbmemo1.Text;
ADOCommand1.Parameters[2].value := currentroom;
AdoCommand1.Execute;
end;
procedure TRoomForm.AddRoomClick(Sender: TObject);
begin
currentroom := 12; // so the result of the query does not match the current value
adoquery3.close;
adoquery3.SQL.Clear;
ADOQuery3.SQL.Add('Select max(roomnumber) from Rooms');
adoquery3.Open;
showmessage(inttostr(currentroom));
end;
procedure TRoomForm.FormCreate(Sender: TObject);
begin
database := 'adventure.mdb';
ADOConnection1.KeepConnection := false;
adoconnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+database+';Persist Security Info=False';
adoconnection1.LoginPrompt := false;
adoconnection1.Mode := cmShareDenyNone;
datasource1.DataSet := adoquery1;
datasource2.DataSet := adoquery2;
datasource3.DataSet := adoquery3;
dbmemo1.DataSource := datasource1;
dbedit1.DataSource := datasource1;
dbgrid1.DataSource := datasource2;
dbedit2.DataSource := datasource3;
adoquery1.connection := adoconnection1;
adoquery2.connection := adoconnection1;
adoquery3.Connection := adoconnection1;
DbMemo1.DataField := 'description';
DbEdit1.DataField := 'roomname';
DbEdit2.DataField := 'RoomNumber';
CurrentRoom := 0;
if fileexists(database) then ShowRoom;
end;
Thanks for any help.