我應該如何清除我在C#代碼(Windows Mobile Compact Framework)中每次新SQL調用時分配給new Dataset()
的DataSet?Clear()或Dispose()清除分配給C#中新數據集()的數據集?
目前我使用Clear(),但是我不確定是否應該使用Dispose。什麼是適當的選擇呢?
一些代碼:
內frmA(主要形式,我執行SQL搜索數據庫)保存我的搜索結果到數據庫中,如果計數大於0,我去爲另一種形式frmNewWork
做了一些工作,發現數據:
// search SQL
// declare connectionString and command...
SqlCeDataAdapter adapter = new SqlCeDataAdapter(mCommand);
modFunctions.tempDataset = new NEWDataSet();
adapter.Fill(modFunctions.tempDataset, "item");
foundCount = modFunctions.tempDataset.item.Count;
// Goes off to another form to do somework with that dataset
if (foundCount > 0)
{
frmNewWork myForm = new frmNewWork();
myForm.ShowDialog()
}
現在...當我從myForm
回來,我想明確的是,數據庫,我這樣做,在內部形成GotFocus
功能:
private void frmA_GotFocus(object sender, EventArgs e)
{
// Clear prior tempDataset (was .Clear() originally)
modFunctions.tempDataset.Dispose();
}
郵政編碼,給上下文。 Btw Clear(),Dispose()和新的DataSet()服務於不同的目的 –
對不起,我添加了一些代碼。 – 22332112