• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

Save DBgrid to file (MySql)


I have to export a selection of fields and records of a database and save that selection to an MySql file. The problem is that on the computer where I have to make this selection, MySql is not installed.

The selection of the fields and the records of the used database are visible in a DBgrid. How can I export/save this selection to a MySql file without MySql installed on that computer. The solution should work stand-alone. I mean that it should work without the use of extra DLL, DBE, DBexpert, ...

I hope you understand what I mean.

All info welcome. Thanks.


PS sorry for my poor English
1 Solution
DBgrid does visualization of the data provided to it through a DataSource from a DataSet connected to a DataBase (MySql). So I guess in your question the DataBase is on a remote machine where MySql is installed.
My advice is create a new MySql Database (file) on the remote Computer, then export/save this selection to that MySql file. After that you may Copy / Download the new MySql Database (file) which contains just exported / saved data into the Computer that has not MySql installed ....
ka1aAuthor Commented:
Thank you for youre reaction.

It is on the computer without MySql that the file has to be made. After that we send the file to someone else by email and he has to open the file with MySql. Is there a solution for this problem?

Thanks again.

Wim ten BrinkSelf-employed developerCommented:
Yes, install MySQL... Otherwise you can never create the file.

But as a suggestion, consider saving the data to an XML file or plain CSV textfile. All the receiver would have to do is import the data in his database by any means.

If you don't have MySQL and don't want to have MySQL, then you cannot support MySQL...
You could use a ClientDataset to make a portable dataset.  

If the structure is already defined in MySQL...
Add or use an existing tQuery control that retrieves the structure (and data, if desired) from MySQL
Add a tDataSetProvider and set its DataSset property to the tQuery
Add a tClientDataSet control and set its ProviderName property to the tDatasetProvider
Set the Active property of the tClientDataset control to true. It will open the tQuery, retrieve the records into memory and close the tQuery control.

If the structure is not already defined in MySQL, you'll need to create it yourself.  Cary Jensen has an extensive set of articles on the Borland Developers Network describing creating clientdataset structures at design time and runtime.

Let's call the MySQL computer "local" and the other computer "remote"

While at the local PC, call the ClientDataset's SaveToFile to create a binary or XML file, for example Portable.cds.
While at the remote PC, call the ClientDataSet's LoadFromFile(portable.cds) to retrieve the data, if any.  

I'm not sure what you mean by "selected" records.  If it is only some of the records that are in the local table, then you could have a second clientdataset with the same structure and copy only the "selected" records to it...

while not clientdataset1.eof do
 if <condition is met> then
  for i:=0 to clientdataset1.fieldcount1 do

You will be able to add, remove and edit the records in the local ClientDataSet.  As long as you don't make the tQuery active on the remote PC, you won't need any database support except for midas.  You can compile the midslib.dcu unit into your application to avoid distributing mids.dll with your application.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now