Solved

this row already belongs to this table

Posted on 2006-07-06
5
810 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

628 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