472,952 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

Adding a row to dataset adds two rows to datagrid

Where is the logic error that causes the attached code to adds two rows
instead on one to the datagrid?

The code correctly update the datasource with one row, but the datagrid
gets two new rows.

What can I do to correct this?

There are textboxes on the form where the users will enter data. The
textboxes and the datagrid share the databinding. After the user enters
data into the code behind the save button assembles a datarow and adds
it to the dataset. Then the dataset is updated to the datasource.

You may note that the dataset is containded in a referenced project - a
data access layer (DAL.Tables)

================================================== ======
Private bmb As BindingManagerBase
Private bNewRowPending as Boolean
Private bEditPending as Boolean
Private Sub CreateBindings()
' Code for binding not shown
bmb = Me.BindingContext(localDsTables1.tblJobCustomer)
End Sub

Private Sub AddNewRow() ' Called by btnAddNewRow button
Call ClearDataEntryControlsForNewRow()
bNewRowPending = True
'User enters data into the controls
End Sub

Private Sub SaveRowChanges() ' Save button calls this

' Determine if it is an Added or Edited Row
If bNewRowPending Then

' Code that adds a new row
Call RowToSave() ' See code below
bmb.Position = bmb.Count
Call UpdateDataSet()
bNewRowPending = False
ElseIf bEditPending Then

' Code that saves edited rows
bEditPending = False
End If
End Sub

Private Sub RowToSave()

Me.localDsTables1.tblJobCustomer.AddtblJobCustomer Row( _
Me.lblpkJobCustomerId.ToString, _
Me.txtJobNumber.Text.ToString, _
Me.cboCustomerName.Text.ToStri*ng, _
Me.txtJobDescription.Text.ToString, _
Me.txtJobRefNum.Text.ToString, _
End Sub

Private Sub UpdateDataSet() 'in the DataAccessLayer

'New DataSet to hold changes
Dim dsDataChanges As New DAL.dsTables 'the DataSet

'Stop any current edits

'Get the changes that have been made to the dataset
dsDataChanges = CType(Me.localDsTables1.GetChanges,
DAL.dsTables) 'the DataSet

'Check to see if any changes are pending
If (Not (dsDataChanges) Is Nothing) Then
' Access the update method in the DataAccessLayer
Dim JobCustomerDT As New DAL.Tables
JobCustomerDT. UpdateDataSource (dsDataChanges)

Catch UpdateDataSetException As Exception
Throw UpdateDataSetException
End Try '

End If

=== Code in the DataAccessLayer ===

Public Function UpdateDataSource(ByVal ChangedRows As DAL.dsTables)
As dsTables '<< the xsd
'Check to see if there are any pending changes
If (Not (ChangedRows) Is Nothing) Then
End If
Catch UpdateException As Exception
Throw UpdateException
End Try
Return Me.DataSet11
End Function

================================================== ======

Where is the logic error?

Thank you,

Nov 21 '05 #1
2 1599

This is mostly hard to see.

However the most change is that you have (expressly when you use
autoincrement) filled your dataset again and the new row is added to the old

Nov 21 '05 #2
Thank you for your replay.

I found the error.
Me.lblpkJobCustomerId.ToString*, _ ' <<< Error Here.
Me.lblpkJobCustomerId.Text.ToString*, _ ' <<< Correction

This entered "SystemWIndows.Form.Label, Text: 4c" into my GUID string.
(I was using a form generated GUID for my ID key)
My most foolish mistake was in having the ID field hidden while trying
to troublshoot the problem. With the ID field shown I could then see
the unexpected entry.

Private Sub RowToSave()
Me.localDsTables1.tblJobCustom*er.AddtblJobCustome rRow( _
Me.lblpkJobCustomerId.ToString*, _ ' <<< Error Here.
Me.txtJobNumber.Text.ToString, _
Me.cboCustomerName.Text.ToStri**ng, _
Me.txtJobDescription.Text.ToSt*ring, _
Me.txtJobRefNum.Text.ToString, _
End Sub

Thank you.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one...
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
by: Sebastian Santacroe | last post by:
Hello, I've got a datagrid with two columns and no data. I want to add data programmically (from DB). When I try to use sintax like: dataset.Tables("Department").Rows(0).Item("Percentage Used")...
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
by: rcoco | last post by:
Hi, I'm trying to Insert a new Row on a dagrid. When I did a google search, I got an example on this address: http://www.codeproject.com/ASPNET_DataGrid.asp. I've done mycode as follows: ...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.