473,503 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update-Insert DetailsView, result is duplicating lines

22 New Member
Everytime I edit a record, and hit update I get duplicating lines in my Details View. Here's my If statement:

Expand|Select|Wrap|Line Numbers
  1. If (Len(e.OldValues("AutoNumber")) > 0) Then
  2.             sql = "UPDATE SHIP_LOG SET FileNumber='" & e.NewValues("FileNumber") & "',BOL='" & e.NewValues("BOL") & "',Container='" & e.NewValues("Container") & "',DESTN='" & e.NewValues("DESTN") & "', Comments='" & e.NewValues("Comments") & "' WHERE POD_COMINV='" & e.Keys("POD_COMINV") & "' AND LineIndex='" & e.Keys("LineIndex") & "'"
  3.         Else
  4.             sql = "INSERT INTO SHIP_LOG (POD_COMINV,FileNumber,BOL,Container,DESTN,Comments,LineIndex) VALUES ('" & e.Keys("POD_COMINV") & "','" & e.NewValues("FileNumber") & "','" & e.NewValues("BOL") & "','" & e.NewValues("Container") & "','" & e.NewValues("DESTN") & "','" & e.NewValues("Comments") & "','" & e.Keys("LineIndex") & "')"
  5.         End If
  6.  
Any ideas???

Thanks
Sep 23 '08 #1
4 2381
mldisibio
190 Recognized Expert New Member
Is this code for a System.Data.DataTable update? Please clarify.

Is the data bound to a DataGrid?
What event are you using to trigger this update/insert?

Sounds like you are manually processing updates done manually in a DataGridView.
Do you have an additional DataAdapter.Update() statement that might be automatically updating the modified rows on its own?
Sep 23 '08 #2
Barno77
22 New Member
Is this code for a System.Data.DataTable update? Please clarify.

Is the data bound to a DataGrid?
What event are you using to trigger this update/insert?

Sounds like you are manually processing updates done manually in a DataGridView.
Do you have an additional DataAdapter.Update() statement that might be automatically updating the modified rows on its own?

Yes, the data is bound to a Gridview when I enter INV #.
Event I'm using is DetailsView1_ItemUpdating. No additional Update statement!
Sep 23 '08 #3
Curtis Rutland
3,256 Recognized Expert Specialist
Pl;ease remember to use [code] tags when posting code.

MODERATOR

Just a "by the way," you should learn how to use String.Format for building strings. Either that or System.Text.StringBuilder. Because reading long concatenated strings like that is painful, and hard to debug.
Sep 23 '08 #4
mldisibio
190 Recognized Expert New Member
OK, you are using the actual DetailsView control, which I am not familiar with. Apologies, I thought you meant "details view" in a generic way and might be using a Forms.DataGridView with which I am more familiar.

Hopefully someone with more experience can help you. Nonetheless, sounds like ItemUpdating may be getting called twice...coders familiar with the control know these quirks and will tell you in a heartbeat.

In the meantime, maybe you could add some Trace statements to the ItemUpdating event handler and see if indeed it is getting called twice. Perhaps (longshot) after executing your sql it fires the updating event again? Try removing the "UPDATE part of your logic, so that it only inserts new records. If you don't get a duplicate, then it might mean it was firing an INSERT followed by an UPDATE for some reason.

Good luck.
Sep 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3822
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
17
4971
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
27
2486
by: VK | last post by:
<http://www.jibbering.com/faq/#FAQ3_2> The parts where update, replacement or add-on is needed are in <update> tag. 3.2 What online resources are available? Javascript FAQ sites, please...
9
12952
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
7
2471
by: jaYPee | last post by:
I am having a problem on how to update view from sql server 2000 database. I have tried dataset and sql dataadapter but no luck. I'm using this view in datagrid and i want to update the datagrid if...
3
2394
by: PAUL | last post by:
Hello, I have 2 datasets I am trying to update. The parent table seems to update fine but when I go update the chiled table I get an error message that says I need a related record in the parent...
8
2672
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. ...
1
2513
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
5
2586
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
6
17859
by: rukkie | last post by:
Hi, I have a dynamic HTML page with 4 columns of data, retrieved with PHP from a MySQL database. At the end of every row I have an UPDATE submit button, which activates a php update script to...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
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...
0
5576
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,...
1
5005
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...
0
4670
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...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
377
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...

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.