TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Chris
NA
11
0
How to delete specific DataRow in DataSet?
Nov 28 2006 10:35 AM
Hey guys, I am trying to delete a specific xml datarow with a specific value but it's not working out for me. Here's my code and the error I receive: DataSet ds = new DataSet(); StreamReader sr = new StreamReader(pathToFile + "AlertSettings.xml"); ds.ReadXml(sr); sr.Close(); DataRow rowToDelete = ds.Tables[0].NewRow(); rowToDelete["PublicationToAlert"] = publication; if (ds.Tables[0].Rows.Contains(rowToDelete)) { ds.Tables[0].Rows.Remove(rowToDelete); ds.AcceptChanges(); ds.WriteXml(pathToFile + "AlertSettings.xml", XmlWriteMode.IgnoreSchema); } Here is the error message: "The given DataRow is not in the current DataRowCollection" I want to delete the row where it's value is equal to the "publication" parameter's value that is being passed in. (i.e. rowToDelete["PublicationToAlert"] = publication;) The remove command breaks and so does this line of code: if (ds.Tables[0].Rows.Contains(rowToDelete)) I get the following error with the above line: "Table doesn't have a primary key" Any help would be greatly appreciated. Thanks guys.
Reply
Answers (
8
)
Dynamically adding CheckBox Controls to TabPages
How to customize a datagrid while printing results??