Solved

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

Posted on 2004-04-28
11
333 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 375 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 125 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 375 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

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

749 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