Solved

this row already belongs to this table

Posted on 2006-07-06
5
798 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:jakyll
  • 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:jakyll
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:jakyll
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide Tab Page 3 34
Protecting vb6 & .Net code Obfuscation 18 94
C# Single Form 8 27
Help with LINQ and XML 10 26
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now