DataTable dt= new Datatable();
try {
SqlCommand Cmd = new SqlCommand("sp_getData",SqlCon);
SqlCommand.CommandType= CommandType.StroedProcedure;
SqlCon.Open();
sqlDataReader dr= cmd.ExecuteReader();
dt.Load(dr);
SqlCon.Close();
}
catch(Exception ex) {
}
finally{
dt.Dispose() //
}
return dt;
返回這段代碼合法?......我的方法返回了DataTable對象,所以調用dispose意志保留值後?? ..請解釋一下..處置DataTable對象,我需要從我的方法
你試圖讓在這段代碼中儘可能多的問題?請閱讀「IDisposable」和「使用塊」。你正在離開你的當地人,並且處理你正在返回的唯一事情。 – nvoigt
任何人出於der ?? ..請倒入你的seguegestions .... –
這是不合法的。看到這個姿勢 - http://stackoverflow.com/questions/18869079/datatable-dispose-will-make-it-remove-from-memory –