Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2003, 01:35 PM
Wezley98 Wezley98 is offline
Member
 
Join Date: Jan 2001
Posts: 78
Default dbgrid getting ramdom value

using adodataset and dbgrid to show a ms access database,

I need to be able to pick a ramdom field from a certain column, does anybody know how to help me please.

this is the code i have already :-

procedure TForm1.Button1Click(Sender: TObject);
begin
if level.Text = 'level1' then
with ADODataSet1 do
begin
Filtered := False;
Filter := 'level1 = ' + QuotedStr('True');
Filtered := True;
//New code to go here
pick a ramdom value from column 'action' which is a string field and display it in an editbox.
end;


end;


Thanks
wez
Reply With Quote
  #2  
Old 07-02-2003, 02:15 PM
figueroamar figueroamar is offline
Senior Member
 
Join Date: Jun 2001
Posts: 198
Default RE: dbgrid getting ramdom value

Try this:

procedure TForm1.Button1Click(Sender: TObject);
var
lastrecno:integer;
begin
if level.Text = 'level1' then
with ADODataSet1 do
begin
Filtered := False;
Filter := 'level1 = ' + QuotedStr('True');
Filtered := True;
lastrecno:=RecNo;
RecNo:=random(RecordCount)+1;
youreditbox.text:=fieldbyname('action').asstring;
RecNo:=lastrecno;
end;
end;

I Hope this helps;
Reply With Quote
  #3  
Old 07-02-2003, 02:33 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: dbgrid getting ramdom value

Hi.

You can try using the RandRange Delphi function to get random field numbers. It should be good enought for this purpose.
Example

var
RField : Integer;
begin

Randomize;

//Field 0 is the first field in the Table.
RField := RandomRange(0,AdoDataSet1.Fields.Count-1);

{...Last Line...}
Edit1.Text := AdoDataSet1.Fields[RField].AsString;

end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:10 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.