Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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,021 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 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