JohnLM 22 Posted December 29, 2022 (edited) I'm trying really hard to figure this message out, but can't. What part of the TFDTable 'text must not be empty' that i need to fill in ? 1. I have a form with a memtable and stringgrid on left side of form. 2. Also have a dbgrid with (con, table, query, datasource) components on right side of form. 3. a button to [import] the data from the stringgrid into the dbgrid. Below, is code to import data into the FDTable. I am just trying to learn how to import data through this method. Not trying to do it another method or way. So, I want to know what is the meaning and solution to the 'text must not be empty' part. I don't know what text the message is refering to when i run this code and click on the [import] button, below... thanks. procedure TForm1.btnImportClick(Sender: TObject); begin // ftable.CopyDataSet(memtable, [coStructure, coRestart, coAppend]); end; solved... (partially) - see my posts below, I explained why it was happening and what I did to resolve it. -- 12/29/2022 Friday pm Edited December 29, 2022 by JohnLM Share this post Link to post
programmerdelphi2k 237 Posted December 29, 2022 (edited) John look, StringGrid (FMX/VCL) /Grids (in FMX) works like a mem-Repository! All data, in fact, will be "string" values! Then, if you need export data to "FDTable", you'll go needs a "converter"! You can use "TBatchMove" components: BatchMove, BatchMove(Dataset/Text)Writer, BatchMove(Dataset/Text)Reader to work "directly" on Datasets: TFDMemTable and FDTables! So, in FDMemTable you create the same "fields" that you need export to FDTable: same names (or not), same types. BatchMove do the magic: read data-sources on FDMemtable and write on target-FDTable see sample on https://en.delphipraxis.net/topic/7991-batchmove-using-firedac-missing-fieldnames-and-tablename-solved/?tab=comments#comment-67218 NOTE: FDMemTable can store your data in XML, JSON and FD binary... and you can define it using property: ResourceOptions ->PersistentFileName .... (check the property Persistent[x] ) and right-click on component and save to file... (before, you need create your fields) Edited December 29, 2022 by programmerdelphi2k Share this post Link to post
weirdo12 21 Posted December 29, 2022 Do you have a SELECT query in the Command property of the TFDTable component? Share this post Link to post
JohnLM 22 Posted December 29, 2022 (edited) After some more investigating, it seems that which ever component I use, (fdquery or fdtable), I have the have its SQL text filled out, as in something like "select * from tblBarcodes" for instance. So, the CopyDataSet(memtable, [coStructure, coRestart, coAppend]) feature is not compatible with the TFDMemTable in some way. I already know about and how to use batchmove and other methods for this process above. I was simply trying the copydataset() to see how that works because I've read about it many times and being in this particular case/situation I thought I would try it out. So, working with the TMemTable and FDQuery/FDTable together, is not a good idea for any projects then, if you can't copy from it, the table structure, etc., if I want to then create a actual database file, i.e., SQLite db. Edited December 29, 2022 by JohnLM Share this post Link to post
weirdo12 21 Posted December 29, 2022 15 minutes ago, JohnLM said: So, working with the TMemTable and FDQuery/FDTable together, is not a good idea for any projects then, if you can't copy from it, the table structure, etc., if I want to then create a actual database file, i.e., SQLite db. From what I gather, you were assuming CopyDataSet would automatically create a new table in an SQLite database. Is that correct? Share this post Link to post
JohnLM 22 Posted December 29, 2022 Not quite. The goal was to have a stringgrid and populate it with barcodes that I would scan with my smartphone (android). Then, if I need the data finalized (stored) then I would export it out to a sqlite database on the phone. But first, I would need to visualize the data in some similar grid. And if I like it, I would [save] to a sqlite db on the phone. I might want to edit the data before I export it out, so the second grid would serve that purpose. Yes, I know, I could and should do it in one table/grid but I will be doing a lot of what-ifs and not needing to export or update data in real-time. I feel, in my opinion, that this is my prefered route for this project, until I decide otherwise.., this will do. Share this post Link to post
JohnLM 22 Posted December 29, 2022 And, by the way, I found the solution, just before you posted before my previous post above. Share this post Link to post
JohnLM 22 Posted December 29, 2022 (edited) The solution I found (through trial and error) through the steps below, works. In the fdquery->SQL I added the following: drop table if exists tblBarcodes; create table if not exists tblBarcodes ( IDNo integer, Barcode varchar(255), isle integer, LFRT varchar(2), Row integer, Type varchar(2), Date varchar(21), Desc varchar(255) ) In my form create section, I have this bit of code: var DATABASE_FILE: string; begin DATABASE_FILE := TPath.Combine(TPath.GetDocumentsPath, 'mydb.db'); DATABASE_FILE := 'f:\datasets\mydb.db'; // <-- rem this line out when compiling over to android. <-- Con.Params.Clear; Con.Params.Add('DriverID=SQLite'); Con.Params.Add('Database=' + DATABASE_FILE); //DATABASE_FILE); con.Params.Add('create database'+database_file); Con.ResourceOptions.DefaultParamType := ptOutput; Con.Connected := True; In my [import] tbutton, I have following code: procedure TForm1.btnImportClick(Sender: TObject); begin // import the database into the second grid for review. qry.Close; qry.data := mtable.Data; qry.open; end; Note, the second grid is a dbgrid. Once I convert this portion of code over to the FMX platform (and then Android) the grid will be a stringgrid. The left side grid is the scanned barcodes, the right side grid is the copied grid/contents from the left side grid. Thus, while I debug my actual mobile barcode scanner app (at my job site), I will be running various scanning tests. So, I will be creating and deleting a number of times the contents in the left side grid, and sometimes I may be import it to right side grid, and then posibly save it out to an sqlite db for further review. Note, I have not tested it for mobile. But I plan to soon. Edited December 29, 2022 by JohnLM Share this post Link to post
weirdo12 21 Posted January 3, 2023 On 12/29/2022 at 3:33 PM, JohnLM said: In my [import] tbutton, I have following code: procedure TForm1.btnImportClick(Sender: TObject); begin // import the database into the second grid for review. qry.Close; qry.data := mtable.Data; qry.open; end; I was going to point out the Data property but you said you only wanted to discuss CopyDataSet() 😄 Good to hear you've got a solution. Share this post Link to post