# Export Query Data to a CSV File

Data from a query can be exported to a CSV file, which can be used by other programs.

Note:

This option has the following known limitations:

- Precision on DateTime objects may be lost.
- Any string with a new line or a comma will break the CSV columns.
- Cognex recommends performing tests to ensure accuracy before deploying.

The following code illustrates how to implement this functionality, using the OnClick script point of a Button element on a Page:

    string csvFilePath = "C:\\MyBackup.csv";
    using (StreamWriter sw = File.CreateText(csvFilePath))
    {
        foreach (DataRow row in $Databases.FastDatabase.Results.GetRecent.QueryResults)
        {
            string line = string.Join(",", row.ItemArray.Select(o => o==null ? string.Empty : o.ToString()));
            sw.WriteLine(line);
        }
    }