Solved

Delete Single Dataset Table Row?

Posted on 2009-05-20
3
386 Views
Last Modified: 2012-08-13
I've looked all over the Internet for this answer. Here are my attempts, but always return error on the index. Not sure how to check if index not 0.

                DataView dv = new DataView(ds.table1);
                dv.RowFilter = "Name ='" + listbox1.SelectedValue.ToString() + "'";
                dv.Delete(0);
                ds.table1.AcceptChanges();

                - or -
               
                ds.table1.Select("Name ='" + listbox1.SelectedValue.ToString() + "'")[0].Delete();
                ds.table1.AcceptChanges();
0
Comment
Question by:pointeman
[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
3 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24434238
sorry i havent tried your code but i will implement the same in a little different way
DataRows rows = ds.table1.Select("Name ='" + listbox1.SelectedValue.ToString() + "'");
for (int i = 0; i < rows.Length; i++
{
     rows[i].Delete();
}
ds.table1.AcceptChanges();
0
 

Author Comment

by:pointeman
ID: 24435551
I didn't mention the listbox is bound to a dataset, so that's why I'm having problems. Sorry for the misinformation...
0
 

Accepted Solution

by:
pointeman earned 0 total points
ID: 24435935
Well, I got it to work although it's messy. I had to use the DataRowView to return the correct ListBox SelectedItem.  Any suggestions are appreciated...
DataRowView drv = (DataRowView)listbox1.SelectedItem;
string item = drv["Name"].ToString();

DataView dv = new DataView(ds.table1);
dv.RowFilter = "Name ='" + Item + "'";
dv.Delete(listbox1.SelectedIndex);
ds.table1.AcceptChanges();  
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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