loading data from sql using binding context

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Hello guys i need your help urgently. I need to load data from sql into my form using binding context. i have written this.
Private Sub cmdRequery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRequery.Click
        DBRequery()
        Me.BindingContext(_DataSet.Tables(0)).CancelCurrentEdit()
        Me.BindingContext(_DataSet.Tables(0)).Position = 0
        RefreshData(True)
    End Sub

and i have this form. the data should be in the textboxes and the combobox when i press the requery button.
But the data wont load.
Untitled.png

But the only thing that happens when i press the requery button. is that i get the departmentID , and not the department Namee.
Can anyone help please.
Thank you :)
 
Firstly, you don't load data from SQL because SQL is a programming language for queries, not a database. Do you actually mean SQL Server, which is Microsoft's enterprise-grade RDBMS, or do you mean a SQL query against some other database?

Secondly, you don't load data from a database using the BindingContext property. That property returns a BindingContext object that provides a link between an IList or IListSource object and the control that owns the property. You have to have already have retrieved the data from the database into that data source object. In your case, the data source is a DataTable. As far as the data-binding is concerned, where the data came from originally is irrelevant.

As for the question, if you're not seeing any data then most likely you haven't bound it correctly. You really shouldn't be using the BindingContext property directly anyway. You should be using a BindingSource. You can add a BindingSource to your form in the designer or in code if you prefer. You bind the Datatable to the BindingSource and then the BindingSource to the control(s). You can then then navigate using the BindingSource.

I suggest that you change that and then see if it works. If not, post back and show us your bindings.
 
Back
Top