For example in the form load event:
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
there is one object that is not disposed, it is dt datatable, so if make dispose, the agents comboBox datasource will be cleared!
Generally, how to make dispose for these cases?
Thank You.