Solved

Delete node in treeview and its associated row in a database table

Posted on 2010-11-12
4
339 Views
Last Modified: 2013-12-17
Hi,

I have made this code and the purpose of it is to delete a node in the treeview
and its associated row from the table. The last part does not work.

        private void tbDelNode_Click(object sender, EventArgs e)
        {
            myDataSet.Tables["Customers"].Rows[0].Delete();  <===
            myDataAdapter.Update(myDataSet, "Tree");
        }


Only the line marked with an arrow is not right. I get the message:
Object reference not set to an instance of an object.

Who can help me that when i selec a certain node of a treeview
the treeviewnode and its associated table row will be deleted.

Peter
0
Comment
Question by:peterkiers
  • 3
4 Comments
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 34126495
There are 2 reasons to get the error mentioned.
myDataSet.Tables["Customers"].Rows[0].Delete();

1) May be myDataset is null
2) There is no table with the table name called "Customers"(Check your spelling) in myDataSet
0
 
LVL 1

Author Comment

by:peterkiers
ID: 34126518
oke:

      private void tbDelNode_Click(object sender, EventArgs e)
        {
            myDataSet.Tables["Tree"].Rows[0].Delete();  <===
            myDataAdapter.Update(myDataSet, "Tree");
        }
And now...
0
 
LVL 1

Author Comment

by:peterkiers
ID: 34126522
I have this but it deletes always the first row of the table:

        {

              myDataSet.Tables["Tree"].Rows[0].Delete();  <==================
            myDataAdapter.Update(myDataSet, "Tree");
            tvNotes.SelectedNode.Remove();
        }

Greetings, Peter Kiers
0
 
LVL 1

Author Comment

by:peterkiers
ID: 34126826
Thanks for the info
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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