可以解釋一下使用數據集和完整SQL查詢有何區別?完整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;
之間是數據集,更優選在特定的查詢使用?
除非有更多比我讀出它的問題,很明顯的一點是,SQL查詢需要更少的開銷,離開工作到數據庫服務器。否則,你把這一切都交給客戶,工作就在那裏。更不用說存儲等等了。但是如果你需要整個表格是出於其他原因,那麼這完全改變了這個問題。總之...第二個例子對於明顯的目標是可取的。 – DonBoitnott