Syed_10 0 Newbie Poster

I've asked the same Question here http://stackoverflow.com/questions/34422852/debug-assertion-failed-binary-search-tree

IM IN DESPERATE NEED OF HELP.

Im working on a project, What I want is to get data from a database (MySql) and store it in a Tree. And be able to do insertion, deletion or updates on the nodes, if any of these commands are performed on a tree then changes must reflect on the database as well. (via Windows Form)
UPDATED
This error shows up when I do the search Via search button

Debug Assertion Failed!

here's my tree code:
just showing the insertion module.

Btree.cpp

#include "Btree.h"

        Btree::Btree()
        {
            root = NULL;
            rootnum = NULL;
        }

        Btree::~Btree(){
            delete root;
        }
        bool Btree::isEmpty() const { 
            return root == NULL; 
        }
        bool Btree::isnumEmpty() const {
            return rootnum == NULL;
        }
        string Btree::treeSearch(string name){
            if (name == "Syed")
                MessageBox::Show(" Syed is present ");
            bool found = false;
            if (isEmpty())
            {
                MessageBox::Show( " This Tree is empty! " );
            }

            node* curr;
            node* parent;
            curr = root;

            while (curr != NULL)
            {
                if (curr->strname == name)
                {
                    found = true;
                    return name;
                    break;
                }
                else
                {
                    parent = curr;
                    if (name>curr->strname) curr = curr->right;
                    else curr = curr->left;
                }
            }
            if (!found)
            {
                MessageBox::Show(" Data not found! ");
            }
        }

        void Btree::insert(string d)
        {
            node* t = new node;
            node* parent;
            t->strname = d;
            t->left = NULL;
            t->right = NULL;
            parent = NULL;
            MessageBox::Show(" pointer is in insert ");
            // is this a new tree?
            if (isEmpty()){
                root = t;
                MessageBox::Show(" Root sval chngd ");
        }
            else
            {
                MessageBox::Show(" storing val ");
                //Note: ALL insertions are as leaf nodes
                node* curr;
                curr = root;
                // Find the Node's parent
                while (curr)
                {
                    parent = curr;
                    if (t->strname > curr->strname) curr = curr->right;
                    else curr = curr->left;
                }

                if (t->strname < parent->strname)
                    parent->left = t;
                else
                    parent->right = t;
            }
        }

Btree.h

 #include <iostream>
    #include <string>

    using namespace std;
    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    #ifndef Btree_H
    #define Btree_H
    class Btree{

    private:
        typedef struct node{
            string strname;
            string strnum;
            node* left;
            node* right;
            node* Lnum;
            node* Rnum;
        };
        node* root;
        node* rootnum;
    public:
        //constructor
        Btree();
        ~Btree();
    public: 
            void insert(string);
            void remove(string);
            string treeSearch(string);
        //void insertnum(string);
            bool isEmpty() const;
            bool isnumEmpty() const;
    };



    #endif 

my Form's coding FOR INSERTION:

 private: System::Void FetchData_Click(System::Object^  sender, System::EventArgs^  e) {
    Btree t;
    //String^ a;
    String^ c = "Syed";
    std::string ststring = msclr::interop::marshal_as<std::string>(c);
    t.insert(ststring);
    }

For Search Button coding:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        String^ name = namep->Text;
        //String^ st = namep->Text;
        Btree t;
        //conversion
        std::string ststring = msclr::interop::marshal_as<std::string>(name);
        string iftrue = t.treeSearch(ststring);
        //string iftrue = "Syed";
        String^ str2 = gcnew String(iftrue.c_str());
        if (str2 != "n"){
            String^ constring = L"datasource=localhost;port=3306;username=root;password=bu123";
            MySqlConnection^ conDataBase = gcnew MySqlConnection(constring);
            MySqlCommand^ cmdDataBase = gcnew MySqlCommand("select * from telephone.phonebook where PName = '" + str2 + "';", conDataBase);
            MySqlDataReader^ myReader;
            try{
                conDataBase->Open();
                myReader = cmdDataBase->ExecuteReader();
                if (myReader->Read()){
                    String^ phone = myReader->GetString("PhoneNumber");
                    PN->Text = phone;
                    String^ phone1 = myReader->GetString("PhoneNumber1");
                    PN1->Text = phone1;
                    String^ phone2 = myReader->GetString("PhoneNumber2");
                    PN2->Text = phone2;
                    String^ phonety = myReader->GetString("PhoneNumberType");
                    pt->Text = phonety;
                    String^ phonety1 = myReader->GetString("PhoneNumberType1");
                    pt1->Text = phonety1;
                    String^ phonety2 = myReader->GetString("PhoneNumberType2");
                    pt2->Text = phonety2;
                    String^ cat = myReader->GetString("Category");
                    category->Text = cat;
                    String^ Gender = myReader->GetString("Gender");
                    gender->Text = Gender;
                    String^ Email = myReader->GetString("Email");
                    email->Text = Email;
                    String^ Adres = myReader->GetString("Address");
                    address->Text = Adres;
                    String^ ct = myReader->GetString("City");
                    city->Text = ct;
                }
                else if (!myReader->Read()){
                    MessageBox::Show("No such Name found!");
                }

            }
            catch (Exception^ex){
                MessageBox::Show(ex->Message);
            }
        }
        else 
            MessageBox::Show("No record");
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.