Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:00:26+00:00 2026-05-27T11:00:26+00:00

Brief : I have code which works if I don’t dispose of the BindingSource

  • 0

Brief : I have code which works if I don’t dispose of the BindingSource after it has been assigned to DataGridView.DataSource but breaks if I do dispose it – why? Do I need to worry about disposing this?

Public Sub GridViewUpdate()
        Dim cn As New System.Data.SqlServerCe.SqlCeConnection
        Dim SQL As System.Data.SqlServerCe.SqlCeCommand
        Dim tbl As New DataTable
        Dim adp As System.Data.SqlServerCe.SqlCeDataAdapter
        Dim Bds As New BindingSource

        DataGridView1.Columns.Clear()

        cn.ConnectionString = "Data Source = C:\path\data.sdf"
        SQL = cn.CreateCommand
        SQL.CommandText = "SELECT myfields FROM myTable  ORDER BY field1 DESC, field2 ASC"
        cn.Open()
        adp = New SqlServerCe.SqlCeDataAdapter(SQL)
        adp.Fill(tbl)
        Bds.DataSource = tbl

        DataGridView1.DataSource = Bds

        cn.Close()
        cn.Dispose()
        SQL.Dispose()
        adp.Dispose()
        tbl.Dispose()
        Bds.Dispose()   '*** <<--- This breaks it - GridView becomes empty

End Sub

So, what is going on here? When I set DataGridView1.DataSource = Bds does it just do this as a reference? How does Bds get disposed once the procedure exits? Does garbage collection pick it up if I assign something else to DataGridView1.DataSource? Do I need to worry about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:00:26+00:00Added an answer on May 27, 2026 at 11:00 am

    Ah, got it!

    DataGridView1.DataSource = Bds.DataSource

    I guess using = Bds just creates a reference but = Bds.DataSource does not.

    Disposing the BindingSource does not cause problems this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief background: I have two-step login page, which after step 1 sends one-time code
EDIT: See my working code in the answers below. In brief: I have a
I have a CustomerRelation class which has a method getInstance() and instance variable i.e
In MATLAB, I have a for loop which has a lot of interations to
Brief I have an installation package (MSI based) which attempts to register a dll
I have WPF application, Which works fine on my PC. As this application is
My prob in brief: I have two tables namely category and product. table: category
Brief Idea about the flow : I have say minimum 1 and maximum 18
In brief: Is it ever excusable to have assembly names and class names stored
Brief intro about my requirement. I have an empty JSF dataTable. Now, when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.