Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-11-12
4
Medium Priority
?
345 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 2000 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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

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.
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

810 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