[2008] BindingNavigator\Dataset Problem
Hi,
I'm trying to use a BindingNavigator, with a Dataset I created. I'm getting an error in the form.show event. Given below is my form load event can you please tell me what i am doing wrong here.
The Error I get is "Cannot bind to the property or column Name on the DataSource. Parameter name: dataMember"
Code:
Private Sub frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connection.OpenConnection(Con)
Dim s_SQL As String = "SELECT ListID, [Name] as fName FROM vw_EmployeeNames ORDER BY ListID"
Dim cmd As New Data.SqlClient.SqlCommand(s_SQL, Con)
da.SelectCommand = cmd
Dim ds As New Data.DataSet
da.Fill(ds, "vw_EmployeeNames")
BindingSource.DataMember = "vw_EmployeeNames"
BindingSource.DataSource = ds
BindingNavigator.BindingSource = BindingSource
lblEmpName.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource, "fName", True))
lblEmpID.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.BindingSource, "ListID", True))
End Sub
Re: [2008] BindingNavigator\Dataset Problem
Is the DataSource of your BindingSource definitely Nothing before you execute that code, because that error message would suggest that it's not. Either make sure that the DataSource is Nothing before setting the DataMember or else assign your DataSet to the DataSource first.
Re: [2008] BindingNavigator\Dataset Problem
Thanks for replying.
I have modified my code to
Code:
BindingSource.DataSource = Nothing
BindingSource.DataMember = Nothing
BindingSource.DataMember = "vw_EmployeeNames"
BindingSource.DataSource = ds
BindingNavigator.BindingSource = Nothing
BindingNavigator.BindingSource = BindingSource
but this still doesn't work.
about assigning my DataSet to a DataSource, is there any method to do this without using the "DataSource creation wizard" ?
I tried using the wizard and then if worked fine. But the problem is my connection string keeps changing so I thought of doing this in the programme. :(
Re: [2008] BindingNavigator\Dataset Problem
Thanks for the tip I removed the binding source and inserted a new binding source and now its working. Thanks again