3

Below is my Connectionstring and sucessfully read the data. It will return total rows of my data.

private static async Task<List<OperatorErrorTransaction>> GetDevIndex()
    {
        try
        {
            var currentConnectionDev = new CurrentConnection(Configuration["ConnectionStrings:Default"], currentRequest);
            Console.WriteLine("\nPress the Enter key to exit the application...\n");
            var response = await currentConnectionDev.DbConnection.QuerySafeAsync<OperatorErrorTransaction>(GenerateGetDatabaseIndexQuery());
            return response.ToList();
        }
        catch (Exception ex)
        {
            return new List<OperatorErrorTransaction>();
        }
    }

    private static string GenerateGetDatabaseIndexQuery()
    {
        return @"SELECT * FROM test.operator_error_transaction";
    }

Below is the csv CreateFile function. Right now i looking a way how to implement mysql data into the csv file.

public static void CreateFile(List<OperatorErrorTransaction> result)
    {


        string myFileName = String.Format("{0:yyyy-MM-dd-HHmm}{1}", DateTime.Now, ".csv");
        string myFullPath = Path.Combine("D:\\", myFileName);

        using (var mem = new MemoryStream())
        using (StreamWriter writer = File.CreateText(myFullPath))
        using (var csvWriter = new CsvWriter(writer))
        {
            csvWriter.Configuration.Delimiter = ";";

            csvWriter.WriteField(result);
            csvWriter.NextRecord();



            writer.Flush();
            var result1 = Encoding.UTF8.GetString(mem.ToArray());
            Console.WriteLine(result1);
        }
    }

I have created a class for the variables as well such as public string BetId { get; set; } etc...

jcjc
  • 31
  • 2
  • Possible duplicate of [How to output MySQL query results in CSV format?](https://stackoverflow.com/questions/356578/how-to-output-mysql-query-results-in-csv-format) – jazb Aug 09 '19 at 07:41
  • I mean i would like to export the csv using c# – jcjc Aug 09 '19 at 08:46

0 Answers0