Solved

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

Posted on 2004-04-28
11
323 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 375 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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 125 total points
Comment Utility

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Accepted Solution

by:
shaneholmes earned 375 total points
Comment Utility
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
Comment Utility

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

Expert Comment

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

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now