is there a way to send packet of queries in 1 query to mysql using c# ?开发者_Go百科 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
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.
精彩评论