Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

this row already belongs to this table

Posted on 2006-07-06
5
Medium Priority
?
821 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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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