Solved

How can I copy a rows from a dataview, edit rows and re-insert them back into the underlying dataset

Posted on 2011-02-21
2
1,018 Views
Last Modified: 2012-05-11
I have a dataset that I use to create a view filtered by certain criteria. I then take this view and create a temp. table. I go through the rows in the temp table and change some values and I need to take the rows in the temp table and add them to the original dataset.

What am I missing? My error is noted below in code next to the *****
When I step through the code everything is ok until the line with the error, where I am trying to add the row back to the original dataset


Dim dvView as dataview
Dim m_dstBaseSettings as Dataset
Dim m_ProjCode as String
Dim dtTempTable as DataTable
Dim drRow as Datarow 


dvDataview = m_dstBaseSettings.Tables("BASE_SETTINGS").DefaultView
 dvDataview.RowFilter = "SETTING_DESCRIPTION = 'REQUIRED' OR SETTING_DESCRIPTION = 'REQUIRED_W_DEFAULT'"
 dvDataview.Sort = "SETTING_DESCRIPTION, SETTING_NAME"
 'Create a temporary table so Station_Code can be added
 dtTempTable = dvDataview.ToTable.Copy
 'Loop through temp table
 For Each drRow In dtTempTable.Rows
     'Assign the stationcode to the new project station code
      drRow.Item("STATION_CODE") = m_ProjCode
      drRow.EndEdit()
      m_dstBaseSettings.Tables("BASE_SETTINGS").Rows.Add(drRow) ****ERROR HERE "Row already belongs to another table"

  Next

Open in new window

0
Comment
Question by:imonfireDAMMIT
[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
2 Comments
 
LVL 11

Accepted Solution

by:
srikanthreddyn143 earned 500 total points
ID: 34947450
Row you are trying to add to the m_dstBaseSettings.Tables("BASE_SETTINGS") is referring to dtTempTable and so you are getting that error.

Why dont you create a row for original datatable and assign the values fro mtemp table and add it this way

For Each drRow In dtTempTable.Rows
Dim dr As Datarow = m_dstBaseSettings.Tables("BASE_SETTINGS").NewRow
dr(colname) = drRow(colName)
     'Assign the stationcode to the new project station code
      dr.Item("STATION_CODE") = m_ProjCode
     
      m_dstBaseSettings.Tables("BASE_SETTINGS").Rows.Add(dr)
  Next

0
 
LVL 1

Author Closing Comment

by:imonfireDAMMIT
ID: 34950663
Thank you! I didn't understand why what I was trying to do wasn't working. In my head it made perfect sense :) you saved me from a headache and now I can move on.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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