Solved

this row already belongs to this table

Posted on 2006-07-06
5
800 Views
Last Modified: 2011-10-03
code and error message below - help!!!!  :-)
thanks
--------------------------------------------------------------------------------------------------------------------------

     Dim r1 As brodbsDataSet.fore_forecastRow = BrodbsDataSet.fore_forecast.Newfore_forecastRow      ' fore_forecast_new
        Dim r2 As brodbsDataSet.fore_actualRow = BrodbsDataSet.fore_actual.Newfore_actualRow            ' fore_actual_new
        Dim i%, file$, yr%
        Dim fh As Integer = 0

        My.Application.DoEvents()

        cnt = 0
   
        While Not EOF(fh)
            ss = ""
            ss = LineInput(fh)
            Microsoft.VisualBasic.FileSystem.LineInput(fh)

            cnt = cnt + 1

                r1.BeginEdit()

                r1.cust_code = Trim(Mid(ss, 1, 6))
                r1.fore_year = yr
                r1.prod_code = Trim(Mid(ss, 7, 7))
                If Mid(ss, x0 + dx + 16, 8 * 10) <> "0000000+0000000+0000000+0000000+0000000+0000000+0000000+0000000+0000000+0000000+" Then Debug.WriteLine("blanks: " & Mid(ss, x0 + dx + 16, 8 * 10))
                r1.fore_forecast09 = Int(Mid(ss, x0 + 7, 1) & Mid(ss, x0 + 0, 7))
                r1.fore_forecast10 = Int(Mid(ss, x0 + 15, 1) & Mid(ss, x0 + 8, 7))
                r1.fore_forecast11 = Int(Mid(ss, x0 + 23, 1) & Mid(ss, x0 + 16, 7))
                r1.fore_forecast12 = Int(Mid(ss, x0 + 31, 1) & Mid(ss, x0 + 24, 7))
                r1.fore_forecast01 = Int(Mid(ss, x0 + 39, 1) & Mid(ss, x0 + 32, 7))
                r1.fore_forecast02 = Int(Mid(ss, x0 + 47, 1) & Mid(ss, x0 + 40, 7))
                r1.fore_forecast03 = Int(Mid(ss, x0 + 55, 1) & Mid(ss, x0 + 48, 7))
                r1.fore_forecast04 = Int(Mid(ss, x0 + 63, 1) & Mid(ss, x0 + 56, 7))
                r1.fore_forecast05 = Int(Mid(ss, x0 + 71, 1) & Mid(ss, x0 + 64, 7))
                r1.fore_forecast06 = Int(Mid(ss, x0 + 79, 1) & Mid(ss, x0 + 72, 7))
                r1.fore_forecast07 = Int(Mid(ss, x0 + 87, 1) & Mid(ss, x0 + 80, 7))
                r1.fore_forecast08 = Int(Mid(ss, x0 + 95, 1) & Mid(ss, x0 + 88, 7))
                r1.EndEdit()


                BrodbsDataSet.fore_forecast.Addfore_forecastRow(r1)
                Fore_forecastTableAdapter.Update(BrodbsDataSet.fore_forecast)

                BrodbsDataSet.fore_forecast.AcceptChanges()

                r1.BeginEdit()
                r1.cust_code = Trim(Mid(ss, 1, 6))
                r1.fore_year = yr + 1                                                                                   ' same data with year advanced.
                r1.prod_code = Trim(Mid(ss, 7, 7))
                r1.fore_forecast09 = Int(Mid(ss, x0 + dx + 7, 1) & Mid(ss, x0 + dx + 0, 7))
                r1.fore_forecast10 = Int(Mid(ss, x0 + dx + 15, 1) & Mid(ss, x0 + dx + 8, 7))
                r1.fore_forecast11 = Int(Mid(ss, x0 + dx + 23, 1) & Mid(ss, x0 + dx + 16, 7))
                r1.fore_forecast12 = Int(Mid(ss, x0 + dx + 31, 1) & Mid(ss, x0 + dx + 24, 7))
                r1.fore_forecast01 = Int(Mid(ss, x0 + dx + 39, 1) & Mid(ss, x0 + dx + 32, 7))
                r1.fore_forecast02 = Int(Mid(ss, x0 + dx + 47, 1) & Mid(ss, x0 + dx + 40, 7))
                r1.fore_forecast03 = Int(Mid(ss, x0 + dx + 55, 1) & Mid(ss, x0 + dx + 48, 7))
                r1.fore_forecast04 = Int(Mid(ss, x0 + dx + 63, 1) & Mid(ss, x0 + dx + 56, 7))
                r1.fore_forecast05 = Int(Mid(ss, x0 + dx + 71, 1) & Mid(ss, x0 + dx + 64, 7))
                r1.fore_forecast06 = Int(Mid(ss, x0 + dx + 79, 1) & Mid(ss, x0 + dx + 72, 7))
                r1.fore_forecast07 = Int(Mid(ss, x0 + dx + 87, 1) & Mid(ss, x0 + dx + 80, 7))
                r1.fore_forecast08 = Int(Mid(ss, x0 + dx + 95, 1) & Mid(ss, x0 + dx + 88, 7))
                r1.EndEdit()
               
                BrodbsDataSet.fore_forecast.Addfore_forecastRow(r1)
                 Fore_forecastTableAdapter.Update(BrodbsDataSet.fore_forecast)

                BrodbsDataSet.fore_forecast.AcceptChanges()

*******************
A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll
-----------------------------------------------------------------------------------------------------
Desc: This row already belongs to this table.
Number: 5
Source: System.Data
Line: 0
-----------------------------------------------------------------------------------------------------
0
Comment
Question by:Dan Flood
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:graye
ID: 17053844
The problem is that you're adding the same row twice (just like the error message says)

You could do a simple:

            r1 = new brodbsDataSet.fore_forecastRow

before the 2nd batch of edits/updates
0
 

Author Comment

by:Dan Flood
ID: 17053950
That wouldn't work - hence my problem.  when i try it says:

Error      1      Argument not specified for parameter 'rb' of 'Friend Sub New(rb As System.Data.DataRowBuilder)'.      
0
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 17054272
Ah... an strongly typed dataset, I missed that

       r1 = BrodbsDataSet.fore_forecast.Newfore_forecastRow
0
 

Author Comment

by:Dan Flood
ID: 17055635
Thanks!!  That was the key.  I feel like i'm in grade 1 again :-)

Now the next problem is it is running soo slowly.  almost 4 times slower than my old VB6 code... but I guess thats another question for another day :)

thanks again!
0
 
LVL 41

Expert Comment

by:graye
ID: 17055713
Naaaa... we can keep going.

The normal design of a program like this would be to read a line from the text file, add the record to the DataTable object (but don't do the update just yet!).  Instead, wait until you've read all of the lines and built all of the rows before doing a single Update().   The Update() method will look through all of the rows you've collected and process them at the database all at one time.

Take a look at the following articles... they were kinda written from a VB6 perspective.   It talks a lot about this "disconnected model", where you cache rows up before saving them to the database.

http://home.hot.rr.com/graye/Articles/BeginningADO.htm
http://home.hot.rr.com/graye/Articles/SavingDataADO.htm
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question