0

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.

Javier Brooklyn
  • 624
  • 3
  • 9
  • 25
AymAn AbuOmar
  • 403
  • 1
  • 5
  • 16
  • 2
    You don't have to Dispose DataTables. Check this for more details: http://stackoverflow.com/questions/913228/should-i-dispose-dataset-and-datatable – Learner Feb 05 '13 at 20:09
  • 1
    Should I understand your question, create and assign a FormClosing eventhandler. Inside the eventhandler, add myDataTable.Dispose(). – Tebc Feb 05 '13 at 20:11
  • thank you man , in your link , the writer said "system.data namespace dose not hav unmanaged resources" so dispose is not necessary ! any body can say more about that ? – AymAn AbuOmar Feb 05 '13 at 21:23

1 Answers1

1

the system.data namespace (ADONET) does not contain unmanaged resources. Therefore there is no need to dispose any of those as long as you have not added yourself something special to it