?
Solved

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

Posted on 2004-04-28
11
Medium Priority
?
342 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
  • 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
Independent Software Vendors: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

862 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