?
Solved

ADO example. Can someone show me how to traverse a record set.

Posted on 2004-04-28
11
Medium Priority
?
339 Views
Last Modified: 2010-08-05

I am using Delphi 7. Can someone give an example of traversing a recordset,  for example using the  northwind database in sql server, showing  the customer ID colurm information.

I am looking to read this information into an array

Does anyone know of any good tutorial for ado and delphi???

thanks in advance


Ian
0
Comment
Question by:alchemy9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 11

Assisted Solution

by:shaneholmes
shaneholmes earned 1500 total points
ID: 10944334
var
 Index: Integer;

Index:= 0;
MyADOTable.First;
while not MyADOTable.EOF do
begin
 MyArray[Index]:=  MyADOTable.FieldByName('MyField').asString;
 MyADOTable.Next;
 inc(Index);
end;


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10944345
replace MyADOTable with the name of yout TADOTable component
replace MyField with the field name (example: CustomerId)
replace MYArray with your array name

Shane
0
 

Author Comment

by:alchemy9
ID: 10944409
wow that was amazingly quick thanks

how would I get the result back from this query

SELECT CASE WHEN is_srvrolemember('sysadmin')=1 OR is_member('db_owner')=1 THEN 1 ELSE 0 END AS output


if you can answer this I will put the points upto 500

cheers

Ian
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10944464
WHat do you mean how do you get the result back?

If its a valid query, you can use it in a TADOQuery.

is it valid?

You can test it in your sql server monitor

SHane
0
 
LVL 17

Assisted Solution

by:mokule
mokule earned 500 total points
ID: 10944771

ADOQuery1.Active := False;
ADOQuery1.SQL.Text :=
   'SELECT CASE WHEN is_srvrolemember(''sysadmin'')=1 OR is_member(''db_owner'')=1 THEN 1 ELSE 0 END AS output';
ADOQuery1.Active := True;

Edit1.Text := ADOQuery1.FieldByName('output').AsString;
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 1500 total points
ID: 10944929
or if you are going to use the query for more  than one sql statement than

ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Txt:=
'SELECT CASE WHEN is_srvrolemember(''sysadmin'')=1 OR is_member(''db_owner'')=1 THEN 1 ELSE 0 END AS output';
 if not ADOQuery1.Prepared then
  ADOQuery1.Prepared:= True;
ADOQuery1.Open;

Edit1.Text := ADOQuery1.FieldByName('output').AsString;


SHane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10944960

Is there any difference in Your code, except of course the letter e which You lost? :)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10945088
yeah, how about the prepare statement - or is that invisible on your end....

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10945098
oh and the SQL clear  <SMILE>

like i said... MOKULE, if he is interested in using it for multiple sql's ...


Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10946771
1. When You assigning to Text, Clear is unnecessary in any case.
2. No need to check Prepared as it is always False after assigning to SQL.Text
3. Prepare is performed also when openning.
4. I'm not very sure but preparing such a simple sql without paramaters has rather no sense.
5. Calling prepare explicitly You should also remember to unprepare as the resources are not freed automatically
0
 

Author Comment

by:alchemy9
ID: 10946976
Thankyou both for you comments they have been exeedingly useful, and very quick, most impressive.

FYI, the sql code does work, it checks the user has suffient rights to add an extended stored procedure.


Ian
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question