Solved

this row already belongs to this table

Posted on 2006-07-06
5
797 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

20 Experts available now in Live!

Get 1:1 Help Now