PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
BindingSource.EndEdit - Not updating underlying data source
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
BindingSource.EndEdit - Not updating underlying data source
![]() |
BindingSource.EndEdit - Not updating underlying data source |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I'm having problems updating a dataset. I call the following method to
add a new record: Me.drvZone = Me.ZonesBindingSource.AddNew() Then when I'm done filling in the form, I call: Me.ZonesBindingSource.EndEdit() Me.ZonesTableAdapter.Update(Me.DsZones) Me.DsZones.AcceptChanges() The problem is, even after this, DsZones is not updated at all. The data still seems to be in the ZonesBindingSource somehow though. I'm confused. Can anyone help? Thanks, Dustin |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Try it like this:
Me.ZonesBindingSource.ResetCurrentItem() Me.ZonesBindingSource.EndEdit() I'd tell you what ResetCurrentItem() does, but you can read it for yourself :=) "Dustin Davis" <dustin@davisvillage.com> wrote in message news:e0icKZpLHHA.448@TK2MSFTNGP04.phx.gbl... > I'm having problems updating a dataset. I call the following method to add > a new record: > > Me.drvZone = Me.ZonesBindingSource.AddNew() > > Then when I'm done filling in the form, I call: > > Me.ZonesBindingSource.EndEdit() > Me.ZonesTableAdapter.Update(Me.DsZones) > Me.DsZones.AcceptChanges() > > The problem is, even after this, DsZones is not updated at all. The data > still seems to be in the ZonesBindingSource somehow though. I'm confused. > Can anyone help? > > Thanks, > Dustin |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Darn, still no luck
![]() I watching in the debugger and I see the following: Before AddNew(): DsZones.Tables(0).Rows.Count = 4 ZonesBindingSource.Count = 4 After AddNew(): DsZones.Tables(0).Rows.Count = 4 ZonesBindingSource.Count = 5 After EndEdit(), & Update(): DsZones.Tables(0).Rows.Count = 4 ZonesBindingSource.Count = 5 So somehow I can't figure out how to update DsZones with my binding source. Earl wrote: > Try it like this: > > Me.ZonesBindingSource.ResetCurrentItem() > Me.ZonesBindingSource.EndEdit() > > I'd tell you what ResetCurrentItem() does, but you can read it for yourself > :=) > > "Dustin Davis" <dustin@davisvillage.com> wrote in message > news:e0icKZpLHHA.448@TK2MSFTNGP04.phx.gbl... >> I'm having problems updating a dataset. I call the following method to add >> a new record: >> >> Me.drvZone = Me.ZonesBindingSource.AddNew() >> >> Then when I'm done filling in the form, I call: >> >> Me.ZonesBindingSource.EndEdit() >> Me.ZonesTableAdapter.Update(Me.DsZones) >> Me.DsZones.AcceptChanges() >> >> The problem is, even after this, DsZones is not updated at all. The data >> still seems to be in the ZonesBindingSource somehow though. I'm confused. >> Can anyone help? >> >> Thanks, >> Dustin > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
I'm not sure why, but if I put the following two lines before EndEdit()
it saves the data to the database: Me.ZonesBindingSource.AddNew() Me.ZonesBindingSource.CancelEdit() Dustin Davis wrote: > Darn, still no luck ![]() > > I watching in the debugger and I see the following: > > Before AddNew(): > DsZones.Tables(0).Rows.Count = 4 > ZonesBindingSource.Count = 4 > > After AddNew(): > DsZones.Tables(0).Rows.Count = 4 > ZonesBindingSource.Count = 5 > > After EndEdit(), & Update(): > DsZones.Tables(0).Rows.Count = 4 > ZonesBindingSource.Count = 5 > > So somehow I can't figure out how to update DsZones with my binding source. > > Earl wrote: >> Try it like this: >> >> Me.ZonesBindingSource.ResetCurrentItem() >> Me.ZonesBindingSource.EndEdit() >> >> I'd tell you what ResetCurrentItem() does, but you can read it for >> yourself :=) >> >> "Dustin Davis" <dustin@davisvillage.com> wrote in message >> news:e0icKZpLHHA.448@TK2MSFTNGP04.phx.gbl... >>> I'm having problems updating a dataset. I call the following method >>> to add a new record: >>> >>> Me.drvZone = Me.ZonesBindingSource.AddNew() >>> >>> Then when I'm done filling in the form, I call: >>> >>> Me.ZonesBindingSource.EndEdit() >>> Me.ZonesTableAdapter.Update(Me.DsZones) >>> Me.DsZones.AcceptChanges() >>> >>> The problem is, even after this, DsZones is not updated at all. The >>> data still seems to be in the ZonesBindingSource somehow though. I'm >>> confused. Can anyone help? >>> >>> Thanks, >>> Dustin >> >> |
|
|
|
#5 |
|
Guest
Posts: n/a
|
That's a kludge, and I wouldn't do it just because it works.
Can you check the RowState of the new record and see if it is, indeed, set as an Insert and not an Update? Is dsZones a strongly typed dataset that you designed with the DataSet Designer? Is the ZonesTableAdapter one that you set up, or did it come from the DataSet Designer, too? Does it actually have the update logic for Inserting records built in? If you change the values in a row and call Update on the table adapter, do they get updated? Is the primary key of the table included in the dataset? Robin S. ------------------------------------- "Dustin Davis" <dustin@davisvillage.com> wrote in message news:uITtpoqLHHA.4376@TK2MSFTNGP03.phx.gbl... > I'm not sure why, but if I put the following two lines before > EndEdit() it saves the data to the database: > > Me.ZonesBindingSource.AddNew() > Me.ZonesBindingSource.CancelEdit() > > Dustin Davis wrote: >> Darn, still no luck ![]() >> >> I watching in the debugger and I see the following: >> >> Before AddNew(): >> DsZones.Tables(0).Rows.Count = 4 >> ZonesBindingSource.Count = 4 >> >> After AddNew(): >> DsZones.Tables(0).Rows.Count = 4 >> ZonesBindingSource.Count = 5 >> >> After EndEdit(), & Update(): >> DsZones.Tables(0).Rows.Count = 4 >> ZonesBindingSource.Count = 5 >> >> So somehow I can't figure out how to update DsZones with my binding >> source. >> >> Earl wrote: >>> Try it like this: >>> >>> Me.ZonesBindingSource.ResetCurrentItem() >>> Me.ZonesBindingSource.EndEdit() >>> >>> I'd tell you what ResetCurrentItem() does, but you can read it for >>> yourself :=) >>> >>> "Dustin Davis" <dustin@davisvillage.com> wrote in message >>> news:e0icKZpLHHA.448@TK2MSFTNGP04.phx.gbl... >>>> I'm having problems updating a dataset. I call the following method >>>> to add a new record: >>>> >>>> Me.drvZone = Me.ZonesBindingSource.AddNew() >>>> >>>> Then when I'm done filling in the form, I call: >>>> >>>> Me.ZonesBindingSource.EndEdit() >>>> Me.ZonesTableAdapter.Update(Me.DsZones) >>>> Me.DsZones.AcceptChanges() >>>> >>>> The problem is, even after this, DsZones is not updated at all. The >>>> data still seems to be in the ZonesBindingSource somehow though. >>>> I'm confused. Can anyone help? >>>> >>>> Thanks, >>>> Dustin >>> >>> |
|
|
|
#6 |
|
Guest
Posts: n/a
|
> That's a kludge, and I wouldn't do it just because it works.
> Right, I was just hoping it might help someone help me ![]() > Can you check the RowState of the new record and see if > it is, indeed, set as an Insert and not an Update? > Before and after I call the EndEdit, the RowState says "Detached{1}" Is this a clue? > Is dsZones a strongly typed dataset that you designed > with the DataSet Designer? > Yes it is. > Is the ZonesTableAdapter one that you set up, or did it > come from the DataSet Designer, too? It came from the DataSet Designer, I think... > Does it actually > have the update logic for Inserting records built in? > Yes, I believe so. > If you change the values in a row and call Update on the > table adapter, do they get updated? > Um, that's another problem I haven't figured out yet. I'm doing this elsewhere and I tend to get this error often: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records. > Is the primary key of the table included in the dataset? > Yes it is. > Robin S. |
|
|
|
#7 |
|
Guest
Posts: n/a
|
What is me.drvZone? What are you binding the dataset to? Can you post
some more code? Robin S. ----------------------------- "Dustin Davis" <dustin@davisvillage.com> wrote in message news:O46bv0zLHHA.2236@TK2MSFTNGP02.phx.gbl... >> That's a kludge, and I wouldn't do it just because it works. >> > Right, I was just hoping it might help someone help me ![]() > >> Can you check the RowState of the new record and see if >> it is, indeed, set as an Insert and not an Update? >> > Before and after I call the EndEdit, the RowState says "Detached{1}" > > Is this a clue? > >> Is dsZones a strongly typed dataset that you designed >> with the DataSet Designer? >> > Yes it is. > >> Is the ZonesTableAdapter one that you set up, or did it >> come from the DataSet Designer, too? > > It came from the DataSet Designer, I think... > >> Does it actually >> have the update logic for Inserting records built in? >> > Yes, I believe so. > >> If you change the values in a row and call Update on the >> table adapter, do they get updated? >> > Um, that's another problem I haven't figured out yet. I'm doing this > elsewhere and I tend to get this error often: > > Concurrency violation: the UpdateCommand affected 0 of the expected 1 > records. > >> Is the primary key of the table included in the dataset? >> > Yes it is. > >> Robin S. |
|
|
|
#8 |
|
Guest
Posts: n/a
|
me.drvZone is a datarowview
> Private drvZone As DataRowView I fill the table adapter on form load > ' Fill Zones Table Adapter > Try > frmMain.DbConnect() > Me.ZonesTableAdapter.Connection = frmMain.Cnn > Me.ZonesTableAdapter.Fill(Me.DsZones.zones, ProcessID) > Me.ZonesBindingSource.DataSource = Me.DsZones > Me.bmZones = Me.BindingContext(DsZones, "zones") > Catch ex As Exception > MsgBox(ex.Message) > End Try Here is the routine that basically does everything that is not working. The else portion adds the new row, while the if portion should end the edit and update the database. > Private Sub btnNewSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewSave.Click > If Me.btnNewSave.Text = frmZones.SaveButtonText Then > If Not IsNumeric(Me.txtTop.Text) OrElse Not IsNumeric(Me.txtLeft.Text) OrElse Not IsNumeric(Me.txtBottom.Text) OrElse Not IsNumeric(Me.txtRight.Text) Then > MsgBox("Coordinates are missing or invalid. Please select highlight the barcode zone, or enter numeric coordinates manually.", MsgBoxStyle.Information) > Exit Sub > ElseIf txtZoneName.Text.Length = 0 Then > MsgBox("You must give this zone a name before saving it.", MsgBoxStyle.Information) > Me.txtZoneName.Focus() > Exit Sub > Else > Try > ' Not sure why, but the following two lines resolve a bug of not saving the data... > 'Me.ZonesBindingSource.AddNew() > 'Me.ZonesBindingSource.CancelEdit() > > Me.ZonesBindingSource.EndEdit() > Me.ZonesTableAdapter.Update(Me.DsZones) > Catch ex As Exception > MsgBox("Error Saving Changes: " & ex.Message, MsgBoxStyle.Critical) > End Try > End If > Me.EnableZoneFields(False) > Else > Try > Me.drvZone = Me.ZonesBindingSource.AddNew() > drvZone.Item("processes_id") = ProcessID > drvZone.Item("split_zone") = 0 > drvZone.Item("kf_field_id") = 0 > Me.EnableZoneFields() > Catch ex As Exception > MsgBox("Error adding new zone: " & ex.Message, MsgBoxStyle.Exclamation) > End Try > End If > End Sub RobinS wrote: > What is me.drvZone? What are you binding the dataset to? Can you post > some more code? > > Robin S. > ----------------------------- > > "Dustin Davis" <dustin@davisvillage.com> wrote in message > news:O46bv0zLHHA.2236@TK2MSFTNGP02.phx.gbl... >>> That's a kludge, and I wouldn't do it just because it works. >>> >> Right, I was just hoping it might help someone help me ![]() >> >>> Can you check the RowState of the new record and see if >>> it is, indeed, set as an Insert and not an Update? >>> >> Before and after I call the EndEdit, the RowState says "Detached{1}" >> >> Is this a clue? >> >>> Is dsZones a strongly typed dataset that you designed >>> with the DataSet Designer? >>> >> Yes it is. >> >>> Is the ZonesTableAdapter one that you set up, or did it >>> come from the DataSet Designer, too? >> It came from the DataSet Designer, I think... >> >>> Does it actually >>> have the update logic for Inserting records built in? >>> >> Yes, I believe so. >> >>> If you change the values in a row and call Update on the >>> table adapter, do they get updated? >>> >> Um, that's another problem I haven't figured out yet. I'm doing this >> elsewhere and I tend to get this error often: >> >> Concurrency violation: the UpdateCommand affected 0 of the expected 1 >> records. >> >>> Is the primary key of the table included in the dataset? >>> >> Yes it is. >> >>> Robin S. > > |
|
|
|
#9 |
|
Guest
Posts: n/a
|
What is bmZones?
What is this about? Me.ZonesTableAdapter.Fill(Me.DsZones.Zones, ProcessID) When I used strongly typed dataset, the Fill only takes one argument. Do you have Option Strict on? I don't understand the use of the BIndingContext. Are you using ..Net 1.1 and VS2003, or .Net 2.0 and VS2005? Robin S. ---------------------- "Dustin Davis" <dustin@davisvillage.com> wrote in message news:%232HzqK2LHHA.320@TK2MSFTNGP06.phx.gbl... > me.drvZone is a datarowview >> Private drvZone As DataRowView > > I fill the table adapter on form load >> ' Fill Zones Table Adapter >> Try >> frmMain.DbConnect() >> Me.ZonesTableAdapter.Connection = frmMain.Cnn >> Me.ZonesTableAdapter.Fill(Me.DsZones.zones, ProcessID) >> Me.ZonesBindingSource.DataSource = Me.DsZones >> Me.bmZones = Me.BindingContext(DsZones, "zones") >> Catch ex As Exception >> MsgBox(ex.Message) >> End Try > > Here is the routine that basically does everything that is not > working. The else portion adds the new row, while the if portion > should end the edit and update the database. >> Private Sub btnNewSave_Click(ByVal sender As System.Object, ByVal e >> As System.EventArgs) Handles btnNewSave.Click >> If Me.btnNewSave.Text = frmZones.SaveButtonText Then >> If Not IsNumeric(Me.txtTop.Text) OrElse Not >> IsNumeric(Me.txtLeft.Text) OrElse Not IsNumeric(Me.txtBottom.Text) >> OrElse Not IsNumeric(Me.txtRight.Text) Then >> MsgBox("Coordinates are missing or invalid. Please select >> highlight the barcode zone, or enter numeric coordinates manually.", >> MsgBoxStyle.Information) >> Exit Sub >> ElseIf txtZoneName.Text.Length = 0 Then >> MsgBox("You must give this zone a name before saving >> it.", MsgBoxStyle.Information) >> Me.txtZoneName.Focus() >> Exit Sub >> Else >> Try >> ' Not sure why, but the following two lines resolve a >> bug of not saving the data... >> 'Me.ZonesBindingSource.AddNew() >> 'Me.ZonesBindingSource.CancelEdit() >> >> Me.ZonesBindingSource.EndEdit() >> Me.ZonesTableAdapter.Update(Me.DsZones) >> Catch ex As Exception >> MsgBox("Error Saving Changes: " & ex.Message, >> MsgBoxStyle.Critical) >> End Try >> End If >> Me.EnableZoneFields(False) >> Else >> Try >> Me.drvZone = Me.ZonesBindingSource.AddNew() >> drvZone.Item("processes_id") = ProcessID >> drvZone.Item("split_zone") = 0 >> drvZone.Item("kf_field_id") = 0 >> Me.EnableZoneFields() >> Catch ex As Exception >> MsgBox("Error adding new zone: " & ex.Message, >> MsgBoxStyle.Exclamation) >> End Try >> End If >> End Sub > > > > RobinS wrote: >> What is me.drvZone? What are you binding the dataset to? Can you post >> some more code? >> >> Robin S. >> ----------------------------- >> >> "Dustin Davis" <dustin@davisvillage.com> wrote in message >> news:O46bv0zLHHA.2236@TK2MSFTNGP02.phx.gbl... >>>> That's a kludge, and I wouldn't do it just because it works. >>>> >>> Right, I was just hoping it might help someone help me ![]() >>> >>>> Can you check the RowState of the new record and see if >>>> it is, indeed, set as an Insert and not an Update? >>>> >>> Before and after I call the EndEdit, the RowState says "Detached{1}" >>> >>> Is this a clue? >>> >>>> Is dsZones a strongly typed dataset that you designed >>>> with the DataSet Designer? >>>> >>> Yes it is. >>> >>>> Is the ZonesTableAdapter one that you set up, or did it >>>> come from the DataSet Designer, too? >>> It came from the DataSet Designer, I think... >>> >>>> Does it actually >>>> have the update logic for Inserting records built in? >>>> >>> Yes, I believe so. >>> >>>> If you change the values in a row and call Update on the >>>> table adapter, do they get updated? >>>> >>> Um, that's another problem I haven't figured out yet. I'm doing this >>> elsewhere and I tend to get this error often: >>> >>> Concurrency violation: the UpdateCommand affected 0 of the expected >>> 1 records. >>> >>>> Is the primary key of the table included in the dataset? >>>> >>> Yes it is. >>> >>>> Robin S. >> |
|
|
|
#10 |
|
Guest
Posts: n/a
|
> What is bmZones?
> bmZones is a BindingManagerBase that I tried and couldn't get to work either. > What is this about? > Me.ZonesTableAdapter.Fill(Me.DsZones.Zones, ProcessID) > When I used strongly typed dataset, the Fill only takes one argument. > My SQL statement to fill the dataset contains "WHERE process_id = @process_id" so I have to pass in a process id > Do you have Option Strict on? > Nope > I don't understand the use of the BIndingContext. Are you using > .Net 1.1 and VS2003, or .Net 2.0 and VS2005? > VS2005 I think I may have found a suitable solution that is not so kludgy. When I'm adding, before the update I call: > Me.DsZones.zones.Rows.Add(drvZone.Row) > Me.ZonesBindingSource.CancelEdit() Then call the Update method. This seems to work for me. Thanks for all your help! > Robin S. > ---------------------- > "Dustin Davis" <dustin@davisvillage.com> wrote in message > news:%232HzqK2LHHA.320@TK2MSFTNGP06.phx.gbl... >> me.drvZone is a datarowview >>> Private drvZone As DataRowView >> I fill the table adapter on form load >>> ' Fill Zones Table Adapter >>> Try >>> frmMain.DbConnect() >>> Me.ZonesTableAdapter.Connection = frmMain.Cnn >>> Me.ZonesTableAdapter.Fill(Me.DsZones.zones, ProcessID) >>> Me.ZonesBindingSource.DataSource = Me.DsZones >>> Me.bmZones = Me.BindingContext(DsZones, "zones") >>> Catch ex As Exception >>> MsgBox(ex.Message) >>> End Try >> Here is the routine that basically does everything that is not >> working. The else portion adds the new row, while the if portion >> should end the edit and update the database. >>> Private Sub btnNewSave_Click(ByVal sender As System.Object, ByVal e >>> As System.EventArgs) Handles btnNewSave.Click >>> If Me.btnNewSave.Text = frmZones.SaveButtonText Then >>> If Not IsNumeric(Me.txtTop.Text) OrElse Not >>> IsNumeric(Me.txtLeft.Text) OrElse Not IsNumeric(Me.txtBottom.Text) >>> OrElse Not IsNumeric(Me.txtRight.Text) Then >>> MsgBox("Coordinates are missing or invalid. Please select >>> highlight the barcode zone, or enter numeric coordinates manually.", >>> MsgBoxStyle.Information) >>> Exit Sub >>> ElseIf txtZoneName.Text.Length = 0 Then >>> MsgBox("You must give this zone a name before saving >>> it.", MsgBoxStyle.Information) >>> Me.txtZoneName.Focus() >>> Exit Sub >>> Else >>> Try >>> ' Not sure why, but the following two lines resolve a >>> bug of not saving the data... >>> 'Me.ZonesBindingSource.AddNew() >>> 'Me.ZonesBindingSource.CancelEdit() >>> >>> Me.ZonesBindingSource.EndEdit() >>> Me.ZonesTableAdapter.Update(Me.DsZones) >>> Catch ex As Exception >>> MsgBox("Error Saving Changes: " & ex.Message, >>> MsgBoxStyle.Critical) >>> End Try >>> End If >>> Me.EnableZoneFields(False) >>> Else >>> Try >>> Me.drvZone = Me.ZonesBindingSource.AddNew() >>> drvZone.Item("processes_id") = ProcessID >>> drvZone.Item("split_zone") = 0 >>> drvZone.Item("kf_field_id") = 0 >>> Me.EnableZoneFields() >>> Catch ex As Exception >>> MsgBox("Error adding new zone: " & ex.Message, >>> MsgBoxStyle.Exclamation) >>> End Try >>> End If >>> End Sub >> >> >> RobinS wrote: >>> What is me.drvZone? What are you binding the dataset to? Can you post >>> some more code? >>> >>> Robin S. >>> ----------------------------- >>> >>> "Dustin Davis" <dustin@davisvillage.com> wrote in message >>> news:O46bv0zLHHA.2236@TK2MSFTNGP02.phx.gbl... >>>>> That's a kludge, and I wouldn't do it just because it works. >>>>> >>>> Right, I was just hoping it might help someone help me ![]() >>>> >>>>> Can you check the RowState of the new record and see if >>>>> it is, indeed, set as an Insert and not an Update? >>>>> >>>> Before and after I call the EndEdit, the RowState says "Detached{1}" >>>> >>>> Is this a clue? >>>> >>>>> Is dsZones a strongly typed dataset that you designed >>>>> with the DataSet Designer? >>>>> >>>> Yes it is. >>>> >>>>> Is the ZonesTableAdapter one that you set up, or did it >>>>> come from the DataSet Designer, too? >>>> It came from the DataSet Designer, I think... >>>> >>>>> Does it actually >>>>> have the update logic for Inserting records built in? >>>>> >>>> Yes, I believe so. >>>> >>>>> If you change the values in a row and call Update on the >>>>> table adapter, do they get updated? >>>>> >>>> Um, that's another problem I haven't figured out yet. I'm doing this >>>> elsewhere and I tend to get this error often: >>>> >>>> Concurrency violation: the UpdateCommand affected 0 of the expected >>>> 1 records. >>>> >>>>> Is the primary key of the table included in the dataset? >>>>> >>>> Yes it is. >>>> >>>>> Robin S. > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 



