Results 1 to 5 of 5

Thread: update bindingsource

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    update bindingsource

    I have a dataset (dS), adapter(aD) and bindingsource(bS) I am using in a form. The datasource for bS is dS, and I am filling the adapter in the form's Load event with a table (tbl) from the dataset.

    On the form I have a listbox and a textbox with the following properties set

    ListBox.DataSource = bS
    ListBox.DisplayMember = <coloumn 1 of tbl>

    The textbox.text property is bound to <column 2 of tbl>

    When I change the selected item of the listbox, the text in the textbox changes to the appropriate data from the dataset, so I know that part of what I am doing works.

    When I change the text in the textbox however, the database is not updating, and I assume I am missing something small.
    my code....

    vb Code:
    1. Public Class RecipeTypesForm
    2.  
    3.     Private Sub RecipeTypesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         Me.RecipeTypesTableTableAdapter.Fill(Me.BrewBaseDataSet.RecipeTypesTable)
    6.  
    7.     End Sub
    8.  
    9.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    10.  
    11.         Dim i As Integer = ListBox1.SelectedIndex
    12.         If i > -1 Then
    13.             Me.RecipeTypesTableBindingSource.Position = i
    14.         End If
    15.  
    16.     End Sub
    17.  
    18.     Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
    19.  
    20.         Me.RecipeTypesTableTableAdapter.Update(Me.BrewBaseDataSet.RecipeTypesTable)
    21.         Me.Close()
    22.  
    23.     End Sub
    24.  
    25. End Class
    I am guessing I am not updating something correctly to finalize the change in the database when I close the form. Can any one see what I am not doing right?
    thanks
    kevin
    Last edited by kebo; Oct 25th, 2010 at 11:49 AM.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: update bindingsource

    Try adding a line where you tell the program you have stopped editing the data before updating the table.

    Code:
    Me.Validate()
    Me.RecipeTypesTableBindingSource.EndEdit
    What this does is that it Applies pending changes to the underlying data source.
    Last edited by kaliman79912; Oct 17th, 2010 at 01:23 PM.

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: update bindingsource

    Sweet kaliman... I thought it would be something small
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  4. #4

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: update bindingsource

    So I was working on this some more, and added a Join to the adapters SELECT statement, and now I get a design exception at Me.RecipeTypesTableTableAdapter.Update(Me.BrewBaseDataSet.RecipeTypesTable)

    vb Code:
    1. Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
    2.  
    3.         Me.RecipeTypesTableTableAdapter.Update(Me.BrewBaseDataSet.RecipeTypesTable) '<====Update is not a member of....blah blah
    4.  
    5.         Me.Close()
    6.  
    7.     End Sub
    I am using the TableAdapter Configuration Wizard to and found this post that indicates the Wizard won't create an UPDATE if the query joins multiple tables. So I need to write the UPDATE command and am not sure of the syntax. This is what I have so far, but don't know what to put in the set parameters...

    Code:
    UPDATE       RecipeTypesTable
    SET                RecipeTypeName =equals what?,
                       RecipeTypeDescription =equals what?,
                       Comment =equals what?
    FROM            RecipeTypesTable INNER JOIN
                             CommentsTable ON RecipeTypesTable.Comment = CommentsTable.CommentID
    Can someone explain what I am supposed to set the columns to to make this command work?
    thanks
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

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

    Re: update bindingsource

    Quote Originally Posted by kebo View Post
    I am filling the adapter in the form's Load event with a table (tbl) from the dataset.
    That's like saying that you're filling a tap with a bucket. The DataTable is what's getting filled and the TableAdapter is what is doing the filling.

    As for your last question, it has nothing to do with the topic of this thread so it doesn't belong in this thread. Please keep each thread to a single topic and each topic to a single thread.

    There's no FROM clause in an UPDATE statement. The SELECT statement is where the FROM clause goes and that's where the JOIN occurs. The UPDATE statement only knows about the table it's updating. Follow the CodeBank link in my signature and check out my Retrieving & Saving Data thread. There's a code example there of creating an UpdateCommand with parameters. Your SQL code needs to follow that pattern and you need to add the corresponding parameters, although you'll add the parameters in the designer rather then in code.
    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

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