CritterLover
Programmer
On a separate screen the user inputs search criteria
and the records are displayed in a listview. Then the
person chooses a record to view on this screen. The
SQL and the itemindex are passed to this screen.
This screen creates a NEW recordset with the same SQL
as the prior search criteria and moves to the desired
record in that recordset and displays the data. I want
to be able to move (forward and backward) through that
recordset using the buttons. We are using Delphi 7 and
MSSQL Server 2005. I have confirmed that it is retrieving
the desired records and I can move forward, but not backwards.
I get
"Operation is not allowed in this context."
There were references to a driver, but this link is no
longer there.
Here's the code:
I know I'm missing something and just haven't been able to figure it out. Thanks in advance.
and the records are displayed in a listview. Then the
person chooses a record to view on this screen. The
SQL and the itemindex are passed to this screen.
This screen creates a NEW recordset with the same SQL
as the prior search criteria and moves to the desired
record in that recordset and displays the data. I want
to be able to move (forward and backward) through that
recordset using the buttons. We are using Delphi 7 and
MSSQL Server 2005. I have confirmed that it is retrieving
the desired records and I can move forward, but not backwards.
I get
"Operation is not allowed in this context."
There were references to a driver, but this link is no
longer there.
Here's the code:
Code:
var
frmTapeDetail: TfrmTapeDetail;
ret_rs: _Recordset; // This is public declarations
vsql: string; // sql statement from prior screen
vrecnum: integer; // ItemIndex to go to desired record
procedure TfrmTapeDetail.RetRecs;
var i: integer;
begin
i := 0;
ret_rs := CoRecordset.Create;
ret_rs.CursorLocation := adUseClient; // I tried these based on internet searches
ret_rs.CursorType := adOpenDynamic;
ssConn.ExecuteSQLStmt(vsql, ret_rs);
If (ret_rs.BOF) and (ret_rs.EOF) Then
begin
ShowMessage('Records not found');
exit;
end;
ret_rs.MoveFirst;
while i < vrecnum do
begin
ret_rs.moveNext; // This loops to the desired record
inc(i);
end;
setvalues;
//ret_rs.CursorType := adOpenDynamic; // I tried it here, too, to no avail
end;
procedure TfrmTapeDetail.setValues;
begin
vSysID := VarToStr(ret_rs.Fields['SysID'].Value);
lblStyleData.caption := VarToStr(ret_rs.Fields['tap_cstyle'].Value);
txtCourtType.Text := VarToStr(ret_rs.Fields['tap_crttype'].Value);
txtCourtNumber.Text := VarToStr(ret_rs.Fields['tap_crtloc'].Value);
txtCaseCategory.Text := VarToStr(ret_rs.Fields['tap_casecat'].Value);
txtCaseNumber.Text := VarToStr(ret_rs.Fields['tap_casenbr'].Value);
// etc, etc etc - Sets values on screen for each record - one at a time - This is all fine going FORWARD
end;
procedure TfrmTapeDetail.btnFirstRecClick(Sender: TObject);
begin
if not ret_rs.BOF then
begin
ret_rs.MoveFirst;
if not ret_rs.BOF then
setValues;
end;
end;
procedure TfrmTapeDetail.btnPrevRecClick(Sender: TObject);
begin
if not ret_rs.BOF then
begin
ret_rs.MovePrevious;
if not ret_rs.BOF then
setValues;
end;
end;
procedure TfrmTapeDetail.btnNextRecClick(Sender: TObject);
begin
if not ret_rs.EOF then
begin
ret_rs.MoveNext;
if not ret_rs.EOF then
setValues;
end;
end;
procedure TfrmTapeDetail.btnLastRecClick(Sender: TObject);
begin
if not ret_rs.EOF then
begin
ret_rs.MoveLast;
if not ret_rs.EOF then
setValues;
end;
end;