Solved

Delete Single Dataset Table Row?

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Question! 4 39
Simple Injector with Web Service 4 55
SSRS subreport with parameter 3 48
Can I command line build a C# application? 6 40
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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