Recent

Author Topic: [SOLVED] SQL Returning Record- But only Giving Me 1 Value  (Read 632 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] SQL Returning Record- But only Giving Me 1 Value
« on: May 01, 2019, 12:24:24 pm »
Quick question.

MY SQL is returning the right amount of records. But when I loop through record set and assign a value to a button, its the same value for all the buttons.

CODE (that don't work)

Code: Pascal  [Select][+][-]
  1.  
  2. queryScripts.SQL.Text := 'select DISTINCT(Category) from main ORDER BY Category';
  3.  
  4. queryScripts.PacketRecords:=-1;    //fetch all records
  5. SQLite3Connection1.Open;
  6. SQLTransaction1.Active := True;
  7. queryScripts.Open;
  8.  
  9. For x1:= 1 to dsScripts.dataset.RecordCount do
  10.   begin
  11.     btn1:=TColorSpeedButton.create(nil);
  12.     btn1.Caption:=dsScripts.Dataset.FieldByName('Category').AsString;
  13.  end;
  14.  

What am I missing. My mind is a fog today.
« Last Edit: May 01, 2019, 01:25:43 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SQL Returning Record- But only Giving Me 1 Value
« Reply #1 on: May 01, 2019, 12:33:31 pm »
Figured it out, I tried this earlier but didn't eot. Ptobalbly incrrect coharacter...

Answer... I simply use...
queryScripts.Next; in the loop

CORRECT CODE:

Code: Pascal  [Select][+][-]
  1.  
  2. queryScripts.SQL.Text := 'select DISTINCT(Category) from main ORDER BY Category';
  3.  
  4. queryScripts.PacketRecords:=-1;    //fetch all records
  5. SQLite3Connection1.Open;
  6. SQLTransaction1.Active := True;
  7. queryScripts.Open;
  8.  
  9. For x1:= 1 to dsScripts.dataset.RecordCount do
  10.   begin
  11.     btn1.Caption:=dsScripts.Dataset.FieldByName('Category').AsString;
  12.     queryScripts.Next;
  13.  end;
  14.  
  15.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018