|
-
Jan 4th, 2009, 04:05 AM
#1
Thread Starter
New Member
[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
Last edited by RandanaG; Jan 4th, 2009 at 04:30 AM.
-
Jan 4th, 2009, 04:41 AM
#2
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.
-
Jan 4th, 2009, 05:49 AM
#3
Thread Starter
New Member
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.
-
Jan 5th, 2009, 01:31 AM
#4
Thread Starter
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|