views:

21

answers:

1

Hi, is there a way to send packet of queries in 1 query to mysql using c# ? i mean i got 13 selects, they are not related, so cant union them, they get diffrent type of data. Now i got dbconn, 13x select, dbclose, its not a problem when it works over lan, but over internet it sometimes takes to slow cos of latency (13x select and recive data). Id like to make it with 1 query like:

select xxx from xxx; select zzz from zzz; select yyy from yyy;

and than read foreach table

+2  A: 

You can send multiple statements and get multiple result sets using MySqlDataReader. You can do something like this:

var cmd = new MySqlCommand("...lot of SQL selects...");
using (var reader = cmd.ExecuteReader())
{
    // Go to a 'next result' each time.
    while (reader.NextResult())
    {
        while (reader.Read())
        {
            // Read data from result set.
        }
    }
}

The trick is to use MySqlDataReader.NextResult to skip to the next result set each time. Of course in your situation you know how many result sets you can expect so you shouldn't use a while loop but you get the idea.

Ronald Wildenberg
thats exactly what i need ;) thanks
Cfaniak