none
Problem after show the update data of mysql RRS feed

  • Question

  • public void con()
            {

                List<TeacherRegistrationBEAM> list = bal.showTeacherData();

                listview.Items.Clear();
                foreach(TeacherRegistrationBEAM ob in list){

                    listview.Items.Add(ob);

               }

    i have a method that you are seeing above i have a button called insert whose code is

                            

    string pass = password.Password;
                 beam = new TeacherRegistrationBEAM()
                {
                    Teacherid = teacherid.Text,
                    TeacherName = teachername.Text,
                    Userid = userid.Text,
                    Password = pass,
                    Contact = phonenumber.Text,
                    Email = email.Text
                };


                bal.insertIntoTeacherRegistration(beam);
                bal.insertIntoLogin(userid, pass);

                Clearfields();
                con();

    when i enter data in listview it will clear the previous items and show data in listview  but when i click the update button whose code is  

    string pass = password.Password;
                beam = new TeacherRegistrationBEAM()
                {
                    Teacherid = teacherid.Text,
                    TeacherName = teachername.Text,
                    Userid = userid.Text,
                    Password = pass,
                    Contact = phonenumber.Text,
                    Email = email.Text
                };


                bal.insertIntoTeacherRegistration(beam);
                bal.insertIntoLogin(userid, pass);

                Clearfields();
                con();

    it will give null refrence exception error in this selection part which i use for listview item back in textboxes

                

    TeacherRegistrationBEAM  test = (TeacherRegistrationBEAM)listview.SelectedItem;
                teacherid.Text = test.Teacherid;
                teachername.Text = test.TeacherName;
                userid.Text = test.Userid;
                string check = test.Password;
                password.Password = check;
                phonenumber.Text = test.Contact;
                email.Text = test.Email;

               and highlight the listview.item .Clear method

    please give correct answer for this problem

                                               
    Wednesday, January 10, 2018 2:04 PM

All replies

  • You need to first set a break-point, step through the code to know what line throws the exception and inspect the item that is causing the exception. If you can't determine how to fix it then come back and indicate the line of code causing the issue.

    Using the debugger.

    Also, when posting code use the code button,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Wednesday, January 10, 2018 2:23 PM
    Moderator
  • TeacherRegistrationBEAM  test = (TeacherRegistrationBEAM)listview.SelectedItem;
                teacherid.Text = test.Teacherid;
                teachername.Text = test.TeacherName;
                userid.Text = test.Userid;
                string check = test.Password;
                password.Password = check;
                phonenumber.Text = test.Contact;
                email.Text = test.Email;

    this will give error after call the con method 
               and it highlight the listview.item .Clear method

    Wednesday, January 10, 2018 3:59 PM
  • Hello Yasirmughal,

    You code looks so confusion that I can't get valuable information, and also it includes some custom methods. Right now I have done a simple test between listview.SelectedItems and  listview.item.Clear method. It works with no problem on my side. Please provide more specific code and error message. Or upload your code to github so that I could provide precise support with it.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 11, 2018 8:11 AM
    Moderator
  • sir i am getting mysql database values in listview to do this i use

    con() method

    my problem is when i insert the values in mysql database through class objects and call

    con() method after that to show inserted value i am using listview.Items.Clear() to remove previous items and show new items 

    and to get values back to textboxes i use listview selection changed code

    but when i update that data and again call the con method it gives nullrefrenceexception error in selection changed code and highlight the listview.Items.Clear() method in con() 

    sir i hope you understand my problem please give me correct answer

     

    Thursday, January 11, 2018 6:47 PM
  • Hello Yasirmughal,

    Please, give me the code info. Did you try to use debug tools to trace the listview.Items property. I can't get the valuable information from your description. It seems that the listview.Items is null object resulted in throwing null reference exception. I have done some testes based on your code and description and everything is OK! Please, give me your project so that I can do further test.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 16, 2018 11:20 AM
    Moderator