Link to home
Start Free TrialLog in
Avatar of Jamil Muammar
Jamil Muammar

asked on

ODBC select huge data rows

Dear Experts,
 I'm using ODBC in C# to select data (SQL statement) from a database then to insert these data into CSV file.

How do I improve my code when the SQL result is huge data?

        public Void executeQuery(string query)
        {

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            OdbcCommand dc = new OdbcCommand(query, conn);
            OdbcDataReader reader = dc.ExecuteReader();

            schematab = reader.GetSchemaTable();

            DataTable dt = new DataTable();
            dt.Load(reader);

            reader.Close();

            Insert dt to CSV file

        }

Open in new window



Thanks
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Maybe tell SQL to output the file ?
Your possibilities:
  • Export the result of your select directly to CSV file. Most of SQL Server can do this (MySQL, MSSQL, Oracle etc.)
  • Don't serialize the result of your query into a DataSet/DataTable. Use DataReader to run a loop and export rows one-by-one.
Avatar of Jamil Muammar
Jamil Muammar

ASKER

Hello Máté Farkas,

 Can you please show me the second option, how to code it in my attached code ?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Máté Farkas
Máté Farkas
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial