Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Server 7.0 and Delphi 6, TQuery Field crash...

Status
Not open for further replies.

davidchardonnet

Programmer
Mar 21, 2001
167
FR
Hello everybody,

I use SQL Server 7.0 and Delphi 6 and some of my queries don't work.
I use a TQuery component and the table CHANTIER is stored like that in SQL server.

-------------------------------
Name Data type length
-------------------------------
NO_CHANTIER int 4
NUM_CHANTIER nvarchar 20
LIB_CHANTIER nvarchar 50
-------------------------------

Query2.close;
Query2.SQL.Clear;
Query2.SQL.add('SELECT NO_CHANTIER,NUM_CHANTIER,LIB_CHANTIER FROM CHANTIER');
Query2.open;
i:=1;
while (not (Query2.eof)) do
begin
Listbox1.Items.Add(Query2.Fields[0].AsString); // This one is ok
Listbox1.Items.Add(Query2.Fields[1].AsString); // This one makes my app crash
query2.Next;
end;

And the crash is an 'Index out of bounds', just like the Fields[1] and Fields[2] did not exist...

Does somebody know where the problem is? Do you have an issue?

Thank you for your help...

David CHARDONNET
 
Not much help, but there is nothing wrong with your code, using a paradox table it works fine, so I can only assume it is something to do with SQL server.

To see if you can get around it (maybe it is not auto adding the fields) try referencing the fields by their names:
Listbox1.Items.Add(Query2.FieldByName('No_Chantier').AsString); // This one is ok
Listbox1.Items.Add(Query2.FieldByName('Num_Chantier').AsString); // This one makes my app crash


Other than that I have no idea I'm afraid. Robertio
Alias: Robbie Calder
Software Developer
urc@walkermartyn.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top