例如在表单加载事件中:
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数据表,所以如果make dispose,代理comboBox数据源将被清除!
一般来说,如何处理这些案件?
谢谢。
答案 0 :(得分:1)
system.data命名空间(ADONET)不包含非托管资源。因此,只要你没有添加一些特殊的东西就没有必要处置它们