473,779 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

Circumstances:
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 BindingManagerB ase
Private bNewRowPending as Boolean
Private bEditPending as Boolean
Private Sub CreateBindings( )
' Code for binding not shown
bmb = Me.BindingConte xt(localDsTable s1.tblJobCustom er)
End Sub

Private Sub AddNewRow() ' Called by btnAddNewRow button
bmb.SuspendBind ing()
Call ClearDataEntryC ontrolsForNewRo w()
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()
bmb.ResumeBindi ng()
bNewRowPending = False
ElseIf bEditPending Then

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

Private Sub RowToSave()

Me.localDsTable s1.tblJobCustom er.AddtblJobCus tomerRow( _
Me.lblpkJobCust omerId.ToString , _
Me.txtJobNumber .Text.ToString, _
Me.cboCustomerN ame.Text.ToStri *ng, _
Me.txtJobDescri ption.Text.ToSt ring, _
Me.txtJobRefNum .Text.ToString, _
Me.txtUserNote. 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
Me.BindingConte xt(Me.localDsTa bles1,
"tblJobCustomer ").EndCurrentEd *it()

'Get the changes that have been made to the dataset
dsDataChanges = CType(Me.localD sTables1.GetCha nges,
DAL.dsTables) 'the DataSet

'Check to see if any changes are pending
If (Not (dsDataChanges) Is Nothing) Then
Try
' Access the update method in the DataAccessLayer
Dim JobCustomerDT As New DAL.Tables
JobCustomerDT. UpdateDataSourc e (dsDataChanges)
localDsTables1. Merge(dsDataCha *nges)
localDsTables1. AcceptChanges()

Catch UpdateDataSetEx ception As Exception
Throw UpdateDataSetEx ception
End Try '

End If

=== Code in the DataAccessLayer ===

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

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

Where is the logic error?

Thank you,
Doug

Nov 21 '05 #1
2 1636
Dough,

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

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

I found the error.
Me.lblpkJobCust omerId.ToString *, _ ' <<< Error Here.
Me.lblpkJobCust omerId.Text.ToS tring*, _ ' <<< 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.localDsTable s1.tblJobCustom *er.AddtblJobCu stomerRow( _
Me.lblpkJobCust omerId.ToString *, _ ' <<< Error Here.
Me.txtJobNumber .Text.ToString, _
Me.cboCustomerN ame.Text.ToStri **ng, _
Me.txtJobDescri ption.Text.ToSt *ring, _
Me.txtJobRefNum .Text.ToString, _
Me.txtUserNote. 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

8
749
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 Datatable. No coding by programer, All wizardry. User starts app, opens form, adds (4) records and clicks update.
2
3639
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 a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
4
5482
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 dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
2
2711
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 button, seems simple. I am using ALL visual controls (supposedly to simplify things. If I was not using the visual controls and calling an ExecuteNonQuery no prob. Please look at my code and tell me what I am doing wrong. Also, what are the advatages...
3
4885
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 the best method? Do you have a sample of how to do this?
1
3297
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 days of struggling, I figure asking you all (the experts) will keep me from going down some dark and dangerous road. The project I have is a fairly simple one, in theory anyway. The gist is to create a page where the user enters an IDNumber,...
1
1489
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") = 10 (you can assume the grid is binded to this dataset table) I get an error telling me row 0 does not exist. I'm assuming I need to use a New command to add rows in a
12
6223
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 datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my code: //Function For Importing Data From CSV File public DataSet ConnectCSV(string filetable)
3
2431
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: private void Fill() { DataSet ds=new DataSet(); SqlDataAdapter adapter =new SqlDataAdapter("select * from DashBoard", con);
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.