|
-
Oct 17th, 2010, 12:58 PM
#1
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:
Public Class RecipeTypesForm
Private Sub RecipeTypesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.RecipeTypesTableTableAdapter.Fill(Me.BrewBaseDataSet.RecipeTypesTable)
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim i As Integer = ListBox1.SelectedIndex
If i > -1 Then
Me.RecipeTypesTableBindingSource.Position = i
End If
End Sub
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
Me.RecipeTypesTableTableAdapter.Update(Me.BrewBaseDataSet.RecipeTypesTable)
Me.Close()
End Sub
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
-
Oct 17th, 2010, 01:19 PM
#2
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.
-
Oct 17th, 2010, 01:48 PM
#3
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
-
Oct 25th, 2010, 12:07 PM
#4
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:
Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
Me.RecipeTypesTableTableAdapter.Update(Me.BrewBaseDataSet.RecipeTypesTable) '<====Update is not a member of....blah blah
Me.Close()
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
-
Oct 25th, 2010, 11:10 PM
#5
Re: update bindingsource
 Originally Posted by kebo
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.
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
|