Link to home
Start Free TrialLog in
Avatar of imonfireDAMMIT
imonfireDAMMITFlag for United States of America

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of srikanthreddyn143
srikanthreddyn143

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of imonfireDAMMIT

ASKER

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.