Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete Single Dataset Table Row?

Posted on 2009-05-20
3
Medium Priority
?
402 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

596 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