[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2004-04-28
11
Medium Priority
?
341 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 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