0

I am fairly new to C# and have successfully created a console app which queries my DB and returns the results in groups using the following code:

class Program
{
    static void Main(string[] args)
    {
        string connString = "Server=FakeServer;Database=example;Uid=NotYou;Password=nicetry";
        MySqlConnection conn = new MySqlConnection(connString); //connects to database
        MySqlCommand command = conn.CreateCommand();
        command.CommandText = "select field_pcis_project_number_value, field_pcis_pi_last_name_value, field_pcis_pi_first_name_value, field_pcis_pi_email_email from field_data_field_pcis_project_number pn inner join field_data_field_pcis_pi_last_name ln on pn.entity_id = ln.entity_id inner join field_data_field_pcis_pi_first_name fn on ln.entity_id = fn.entity_id inner join field_data_field_pcis_pi_email em on fn.entity_id=em.entity_id";


        try
        {
            conn.Open();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            throw;
        }
        MySqlDataReader reader = command.ExecuteReader();
        while(reader.Read())
        {
            Console.WriteLine(reader["field_pcis_project_number_value"].ToString());
            Console.WriteLine(reader["field_pcis_pi_last_name_value"].ToString());
            Console.WriteLine(reader["field_pcis_pi_first_name_value"].ToString());
            Console.WriteLine(reader["field_pcis_pi_email_email"].ToString());
            Console.WriteLine("\n");


        }
        Console.ReadLine();

    }

    public void CreateXLSFile(MySqlDataReader dt, string strFileName)
    {


    }



 }

I would now like to export the data into a new excel file and organize the data in such a manner that each Console.WriteLine(reader.. statement is a column and the values are imported into the corresponding columns.

How can I accomplish this?

Thanks in advance!

D0uble0
  • 175
  • 1
  • 2
  • 12
  • Possible duplicate: [Create Excel (.XLS and .XLSX) file from C#](http://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp?rq=1) – Adam Chubbuck May 15 '17 at 19:37
  • Possible duplicate of [Creating excel file in C#](http://stackoverflow.com/questions/11571281/creating-excel-file-in-c-sharp) – T.S. May 15 '17 at 20:26
  • Internet is full of answers for this one – T.S. May 15 '17 at 20:27

0 Answers0