Solved

Delete Single Dataset Table Row?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET URL re-routing tool did I use? 2 56
C# Single Form 8 42
C#  Radio button search for Date not DateTime 4 46
Install Problem 13 30
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

770 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