Solved

Delete Single Dataset Table Row?

Posted on 2009-05-20
3
364 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now