例如在表单加载事件中:
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 数据表,所以如果进行释放,代理的组合框数据源将被清除!
一般来说,如何对这些情况进行处理?
谢谢你。