0
例如在窗体加载事件:如何在表单关闭后处理非托管资源?
Dim Conn As New OleDbConnection(ConnectionString)
Dim dataAdapter As New OleDb.OleDbDataAdapter
Dim dt As New Datatable
Dim Command As New OleDbCommand
Try
Command.CommandText = "select agentName from agents order by agentName"
dataAdapter = New OleDb.OleDbDataAdapter(Command.CommandText, Conn)
dataAdapter.Fill(dt)
agentsV.DataSource = dt
agentsV.ValueMember = "agentName"
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight)
Finally
Conn.Dispose()
dataAdapter.Dispose()
Command.Dispose()
End Try
有是没有设置一个对象,它是DT数据表,因此,如果化妆处置,代理组合框的数据源将被清除!
一般情况下,如何为这些情况进行处理?
谢谢。
您不必Dispose DataTables。 检查了解更多细节:http://stackoverflow.com/questions/913228/should-i-dispose-dataset-and-datatable – Learner
我应该理解你的问题,创建并分配FormClosing事件处理程序。在事件处理程序中,添加myDataTable.Dispose()。 – Tebc
谢谢你,在你的链接中,作者说“system.data命名空间不会拥有非托管资源”,因此不需要配置!任何机构都可以多说一点? –