Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to read data from MySQL using C#

Tags:

c#

mysql

I'm wondering if there is a faster method than using something like:

while (Reader.Read())

to read the results of mysql select queries.

I'm randomly pulling 10,000 rows from a database and would like to read it as quickly as possible. Is there a way to serialize the results if we know what they are (such as using the metadata to setup a structure)?

like image 937
simpleCoder Avatar asked Jan 11 '11 19:01

simpleCoder


People also ask

Can we use MySQL with C?

The C API provides low-level access to the MySQL client/server protocol and enables C programs to access database contents. The C API code is distributed with MySQL and implemented in the libmysqlclient library.

Which query is faster in MySQL?

MySQL full-text search (FTS) is far much faster than queries using wildcard characters.

Is view faster than query MySQL?

Contrary to the answers - In my experience, for views with lots of joins, doing a direct query runs faster.

Can I use C# with MySQL database?

Before you start to connect your application to MySql, you need to add add the mysql Reference in your project. To do so, right click our project name, and choose Add Reference, then choose "MySql. Data" from the list. Next, you need to add MySql Library in your C# project.


1 Answers

Try MySQLDataAdapter.Fill method to fill any DataTable object - read speed is comparable to optimal usage of read data with Read method (depends on your while block reading way) and main advantage is that you achieve prepared data collection which you can manage or just write to XML file.

like image 115
Przemysław Michalski Avatar answered Oct 31 '22 03:10

Przemysław Michalski