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?
Thanks
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
}
Thanks
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.
ASKER
Hello Máté Farkas,
Can you please show me the second option, how to code it in my attached code ?
Thanks
Can you please show me the second option, how to code it in my attached code ?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.