我使用ExecuteScalar
进行单一查询,如下所示:
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();
}
它对我来说很好。但是3(以及其他数据库的更多)查询等待因为数据库太多了。如何选择所有表(从表1中选择*)并在每个where条件下执行命令后?你能举例说明我的示例代码吗?谢谢。