473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Removing elements from a typed dataset

I have the following code whose purpose is to take 2 typed datasets (of type
DSAccounts ) & remove all elements of one from the other. and return what
is left.

However I am getting the error message "The given datarow is not in the
current DataRowCollection" when the "dtAll.tblAccounts.Rows.Remove(dr);"
line executes. I have debugged and found that the data to be deleted is
definitely present in the master dataset.

What am i doing wrong?? Please help!

private DSAccounts RemoveFromDS(DSAccounts dtAll, DSAccounts dtRemove ) {
try {

string account;

foreach (DSAccounts.tblAccountsRow dr in dtRemove.tblAccounts.Rows) {

account = dr[0].ToString();

if (dtAll.tblAccounts.Rows.Contains(account))

dtAll.tblAccounts.Rows.Remove(dr);

}
return dtAll;

}

catch (Exception e) {

throw e;

}
}
Jan 10 '06 #1
3 6822
Have you tried calling AcceptChanges() on the dataset to commit all the
changes that you have just made to it.

Emma

Jan 10 '06 #2
You are Checking DataRow by Key and trying to delete Row. even though
rows in dtAll and dtRemove have same Key Both are diffrent. So you
need to Select Row from dtAll by Key and then try to remove.

e.g Column "Id" has primary Key So select Row by Key and then delete
it

try
{
string account;
for(int i =0; i< dtRemove.DSAccountdt.Rows.Count; i++ )
{
DSAccount.DSAccountdtRow dr =
(DSAccount.DSAccountdtRow)dtRemove.DSAccountdt[i];
account = dr[0].ToString();
if (dtAll.DSAccountdt.Rows.Contains(account))
{
DataRow[] dr1 = dtAll.DSAccountdt.Select("Id=" + account);
dtAll.DSAccountdt.Rows.Remove(dr1[0]);
}

}
return dtAll;
}
Hope It wil work

ABCL

Jan 10 '06 #3
Thank you,ABCL. It works!!

"ABCL" <oh****@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
You are Checking DataRow by Key and trying to delete Row. even though
rows in dtAll and dtRemove have same Key Both are diffrent. So you
need to Select Row from dtAll by Key and then try to remove.

e.g Column "Id" has primary Key So select Row by Key and then delete
it

try
{
string account;
for(int i =0; i< dtRemove.DSAccountdt.Rows.Count; i++ )
{
DSAccount.DSAccountdtRow dr =
(DSAccount.DSAccountdtRow)dtRemove.DSAccountdt[i];
account = dr[0].ToString();
if (dtAll.DSAccountdt.Rows.Contains(account))
{
DataRow[] dr1 = dtAll.DSAccountdt.Select("Id=" + account);
dtAll.DSAccountdt.Rows.Remove(dr1[0]);
}

}
return dtAll;
}
Hope It wil work

ABCL

Jan 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Job Lot | last post by:
I am confused how strongly typed dataset is different from un-typed dataset. Is there any good link explaining pros and cons of both? Which one should be used preferably?
1
by: Nedu N | last post by:
Hi All, I am facing problem in copying content of table from a untyped dataset into to a table inside the typed dataset. I wanted to copy the data into typed dataset in order to ease the further...
1
by: Trond | last post by:
I have a class MessageController that has a method GetMessagesDataset that connects to a database SPROC. When done it returns a dataset. Then in my ASP.NET for i do this: msgController = new...
3
by: Freeon | last post by:
Hi, I am looking for a way to sort a strong typed dataset. It would seem the most straightforward way is to use a dataview. The only problem is when I use the dataview I seem to loose the strong...
1
by: Optimus | last post by:
Hi everyone, I currently develop an application in vs.net 2005 with vb.net. I was trying to use typed dataset and I've got in trouble for converting untyped dataset into Typed DataSet. I don't...
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
4
by: Ronald S. Cook | last post by:
I've always used untyped datasets. In a Microsoft course, it walks through creating typed datasets and harps on the benefits. It has you drag all these things around ..wizard, wizard, wizard......
21
by: Peter Bradley | last post by:
Hi all, This post is sort of tangentially related to my earlier posts on configuration files for DLLs. Does anyone know how to create typed DataSets using VS2005's new DataSet designer, but...
4
by: Rachana | last post by:
Hi, I have understood Data Sets but what is meant by typed/untyped/ strongly typed datasets. Can any one explain me or suggest any site/ article, to get these concepts (and their ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.