0

I use ExecuteScalar for single query like this:

try
{
    OleDbConnection Connection;
    using (Connection = new OleDbConnection("Provider=MSDAORA.1;Data Source=DATABASE:1521/orcl;Persist Security Info=True;Password=PASSWORD;User ID=USERNAME"))
    {
    OleDbCommand Command1, Command2, Command3;

    Command1 = new OleDbCommand("SELECT HOUR FROM Table1 WHERE type='CAR' and name='FERRARI'",", Connection);
    Command2 = new OleDbCommand("SELECT HOUR FROM Table1 WHERE type='CAR' and name='FORD'", Connection);
    Command3 = new OleDbCommand("SELECT HOUR FROM Table1 WHERE type='CAR' and name='OPEL'", Connection);

    Connection.Open();
    var1 = (int)Command1.ExecuteScalar();
    var2 = (int)Command2.ExecuteScalar();
    var3 = (int)Command3.ExecuteScalar();
    Connection.Close();
} 

It's working fine for me. But 3 (and more for other databases) query waiting so much because of database. How can I select all table (select * from Table1) and after execute commands for every where condition? Can you show me example for this on my sample code? Thank you.

onur
  • 5,647
  • 3
  • 23
  • 46

1 Answers1

1

You can send multiple commands to the database at once (separated by semicolons). You can get each result set using OleDb.NextResult(). This will cause one back-and-forth to the database, rather than the three you have now.

Eric J.
  • 147,927
  • 63
  • 340
  • 553