Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Basically, I have this functions in my parent form that retrieves data from a database table. Now, my second form functions as an add form. I want that when I press my second form's add button, it will call the function or executes a code that will refresh/re-retrieve the data into the form 1's listview.

C#
private void loadtbl()
        {
            
                supplier_tb.Items.Clear();
                cn.Open();
                cmd.CommandText = "select * from SupplierTable";
                cmd.Connection = cn;
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    ListViewItem item = new ListViewItem(dr["Supp_ID"].ToString());
                    item.SubItems.Add(dr["Supp_Name"].ToString());
                    item.SubItems.Add(dr["Supp_Address"].ToString());
                    item.SubItems.Add(dr["Supp_CPerson"].ToString());
                    item.SubItems.Add(dr["Supp_TelNo"].ToString());
                    item.SubItems.Add(dr["Supp_FaxNo"].ToString());
                    item.SubItems.Add(dr["Supp_Email"].ToString());
                    item.SubItems.Add(dr["Supp_TIN"].ToString());
                    item.SubItems.Add(dr["Supp_Status"].ToString());
                    item.SubItems.Add(dr["Supp_Term"].ToString());
                    item.SubItems.Add(dr["Supp_Category"].ToString());
                    supplier_tb.Items.Add(item);

                }
                cn.Close();

   }


What I have tried:

Have not tried anything so far, 'cause I'm confused as to how to approach it.
Posted
Updated 12-Jun-18 20:10pm
Comments
Eric Lynch 12-Jun-18 20:49pm    
My recommendation, separate the concerns. Move the common logic into a separate class that either form can call.

 
Share this answer
 
As Eric Lynch[^] mentioned in the comment to the question, you have to separate Data Access Layer[^] and Business Logic Layer[^] into different classes. It's basics.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900