?
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
Medium Priority
?
1,020 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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