0

my problem is that the table that my user will be loading, i'm not sure what they columns will be so how do define these unknown elements (columns), and also what they will be defined as (e.g. asstring, asinteger,asreal) etc (I use SQLlite)

So here's my code

procedure TFrmsearchpage.btnloadClick(Sender: TObject);
var
con:tfdconnection;
loadquery:tfdquery;
i:integer;
j:integer;
row:integer;
col1,col2,col3,col4, col5, col6, col7 : string;

begin
con:=tfdconnection.Create(nil);

loadquery:=tfdquery.Create(con);
loadquery.Connection:=con;
con.DriverName:='SQL';
con.Open('DriverID=SQLite;Database='+Dir+'/Stock_V5;');
loadquery.SQL.Text:='SELECT * FROM ' + edtdatabasename.Text;  //' Con Column';
 loadquery.Open;
  if loadquery.Eof then
    ShowMessage('not exists')
  else
    ShowMessage('exists');

for i := 0 to sgdproduct.RowCount do
    for j := 0 to sgdproduct.ColCount do
      sgdproduct.Cells[i,j]:='';
showmessage(loadquery.SQL.Text);
Sgdproduct.colcount:=7;
sgdproduct.fixedcols:=0;
for i := 0 to 3 do
sgdproduct.colwidths[i]:=100;
sgdproduct.cells[0,0] := 'Col1'; //?
sgdproduct.cells[1,0] := 'Col2';   //?
sgdproduct.cells[2,0] := 'Col3';
sgdproduct.cells[3,0] := 'Col4';  //?
sgdproduct.cells[4,0] := 'Col5';   //?
sgdproduct.cells[5,0] := 'Col6';  //?
sgdproduct.cells[6,0] := 'Col7';  //?
row:=1;
while not loadquery.Eof do
begin
    Col1:=query.FieldByName('Col1')//.As
  Col2:=query.FieldByName('Col2')//.As
  Col3:=query.FieldByName('Col3')//.As
  Col4:=query.FieldByName('Col4')//.As
  Col5:=query.FieldByName('Col5')//.As
 Col6:=query.FieldByName('Col6')//.As
 col7:=query.FieldByName('Col7')//.As
  sgdproduct.Cells[0,row]:=Col1;
   sgdproduct.Cells[1,row]:=Col2;
    sgdproduct.Cells[2,row]:=Col3;
     sgdproduct.Cells[3,row]:=Col4;
     sgdproduct.Cells[4,row]:=Col5;
          sgdproduct.Cells[5,row]:=Col6;
          sgdproduct.Cells[6,row]:=Col7;
      row:=row+1;
      query.Next;
end;
end;
Shadow
  • 33,525
  • 10
  • 51
  • 64
Deadraa
  • 11
  • 1
  • 5
  • 1
    Possible duplicate of [How can I get the list of a columns in a table for a SQLite database?](http://stackoverflow.com/questions/604939/how-can-i-get-the-list-of-a-columns-in-a-table-for-a-sqlite-database) – Shadow Dec 06 '15 at 22:58
  • SQLite uses [dynamic typing](http://www.sqlite.org/datatype3.html); data types can be different in the same column. – CL. Dec 07 '15 at 08:48

1 Answers1

0

to give label in stringgrid based on Tdataset generated by your SQL, take a look at below code :

for i := 0 to DataSet.FieldCount - 1 do
begin
  sgdproduct.cells[i,0] := DataSet.Fields[i].DisplayName;
end;
bagus prasojo
  • 595
  • 5
  • 18
  • Hey, thanks for the help, any idea how i can display all the data from the loaded table under each of the columns inside the StringGrid? – Deadraa Dec 07 '15 at 12:10