Populating a DBGrid or DBEdit lazarus / 16-Databases ---------------------------------------------------------------------- heebiejeebies · 2021-09-06 08:22 Hi all, Well, it seems every time I try something new I have to ask first to get it to work!    Maybe one day I'll figure something out myself.  Latest clumps of hair being torn out have been caused by DBGrid and DBEdit refusing to populate.  I have lots of database functions in my program that work perfectly, so I know the basics of hooking up the various components.  I have a connection, transaction, datasource and query all connected to each other.  The DBGrid and DBEdit have the relevant datasource set.  I have a procedure which I copied from the only datagrid tutorial I could find online, which follows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   UserFileConnection.Open;  UserFileTransaction.Active:= True;  Userdatasource.Enabled :=true;  UserFileLoad.SQL.Text:=('SELECT * FROM IssueTable');  Userdatasource.DataSet:= UserFileLoad;  PPDatagrid.DataSource :=Userdatasource;  PPDatagrid.Autofillcolumns :=true;  DBEdit1.Datafield :='IssueName';  UserFileTransaction.Commit;   UserFileLoad.Open; Have tried putting the DB commands in different orders and so on.  Have tried filtering the select statement by a single rowid.  The above code at least makes it load one lot of blank data, but nothing else.  I get one row of blanks in the datagrid, and the DBEDIT populates with the text '(MEMO)'.  If I insert columns into the datagrid matching the fields of the table then I can get '(MEMO)' to appear there too. Any ideas? ---------------------------------------------------------------------- wp · 2021-09-06 08:32 In order to display a memo field use a TDBMemo control rather than a TDBEdit. ---------------------------------------------------------------------- balazsszekely · 2021-09-06 08:34 Hi heebiejeebies, QuoteWell, it seems every time I try something new I have to ask first to get it to work!    Maybe one day I'll figure something out myself.  Latest clumps of hair being torn out have been caused by DBGrid and DBEdit refusing to populate.  I have lots of database functions in my program that work perfectly, so I know the basics of hooking up the various components.  I have a connection, transaction, datasource and query all connected to each other.  The DBGrid and DBEdit have the relevant datasource set.  I have a procedure which I copied from the only datagrid tutorial I could find online, which follows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   UserFileConnection.Open;  UserFileTransaction.Active:= True;  Userdatasource.Enabled :=true;  UserFileLoad.SQL.Text:=('SELECT * FROM IssueTable');  Userdatasource.DataSet:= UserFileLoad;  PPDatagrid.DataSource :=Userdatasource;  PPDatagrid.Autofillcolumns :=true;  DBEdit1.Datafield :='IssueName';  UserFileTransaction.Commit;   UserFileLoad.Open; Have tried putting the DB commands in different orders and so on.  Have tried filtering the select statement by a single rowid.  The above code at least makes it load one lot of blank data, but nothing else.  I get one row of blanks in the datagrid, and the DBEDIT populates with the text '(MEMO)'.  If I insert columns into the datagrid matching the fields of the table then I can get '(MEMO)' to appear there too. Any ideas? Looks good! The only thing is missing, is the link between the query(UserFileLoad) and the connection(UserFileConnection): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //...UserFileLoad.Database := UserFileConnction; //<-This lineUserFileLoad.Open ---------------------------------------------------------------------- heebiejeebies · 2021-09-06 09:06 Quote from: wp on September 06, 2021, 10:32:33 amIn order to display a memo field use a TDBMemo control rather than a TDBEdit. Thanks!  Still doesn't work though.    Just appears blank, doesn't even give the '(Memo)' like the DBEdit does. ---------------------------------------------------------------------- heebiejeebies · 2021-09-06 09:10 Quote from: GetMem on September 06, 2021, 10:34:27 amHi heebiejeebies, Looks good! The only thing is missing, is the link between the query(UserFileLoad) and the connection(UserFileConnection): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //...UserFileLoad.Database := UserFileConnction; //<-This lineUserFileLoad.Open Thanks GetMem!  I have the database already linked up through the object inspector.  It works this way for all my other queries so I didn't bother putting it in code.  Actually there are probably a few lines in the code I posted that are redundant due to the properties already being set in the object inspector, but I decided to follow the tutorial exactly just to be sure.  Anyway, I tried adding in your database line but I still got the same result. ---------------------------------------------------------------------- balazsszekely · 2021-09-06 09:20 Does your query return any data? Please put a button to your form, then: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  UserFileLoad.First;  while not UserFileLoad.EOF do  begin    ShowMessage(UserFileLoad.FieldByName('IssueName').AsString);    UserFileLoad.Next;  end;end;If yes, then I have no idea what is the problem, you should attach your program to your next post. ---------------------------------------------------------------------- heebiejeebies · 2021-09-06 09:50 Yes it does return the data from that table.  Thanks for your efforts!  I'll see if anyone else has any ideas and if I have no luck I'll attach it, but it'll be a bit of effort just to extract that part since it's part of a large project. ---------------------------------------------------------------------- egsuh · 2021-09-10 05:58 First try to display the content of query just linking DB components. Not using codes. ---------------------------------------------------------------------- heebiejeebies · 2021-09-23 10:45 Quote from: egsuh on September 10, 2021, 07:58:58 amFirst try to display the content of query just linking DB components. Not using codes. I did - it didn't work.