Results 1 to 4 of 4

Thread: [2008] BindingNavigator\Dataset Problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    [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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    3

    Resolved 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
  •  



Click Here to Expand Forum to Full Width