你能解释一下使用数据集和完整的 SQL 查询有什么区别吗?
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Environment.CurrentDirectory + "\\db.accdb");
string cmd = "SELECT * FROM my_table";
conn.Open();
DataSet dset = new DataSet();
OleDbDataAdapter dadapter = new OleDbDataAdapter(cmd, conn);
OleDbCommandBuilder cmdBuilder = new OleDbCommandBuilder(dadapter);
dadapter.Fill(dset, "my_table");
DataTable table = dset.Tables["my_table"];
foreach (DataRow dr in table.Rows)
if ((int)dr["id"] == 123)
return true;
return false;
之间
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Environment.CurrentDirectory + "\\db.accdb");
string cmd = "SELECT 1 FROM my_table WHERE id = 123";
conn.Open();
OleDbCommand command_reader = new OleDbCommand(cmd, conn);
return command_reader.ExecuteScalar() != null;
数据集是否更适合在特定查询中使用?