.Hello guys! I would like to ask for some help regarding one of my class projects.

Here i have two classes named AddBook.cs and the other is ListCommand.cs, what i want to do is to transfer certain codes from AddBook to ListCommand so that whenever i want to use the codes i'm only going to call the class ListCommand to avoid writing the codes again.

Here are the codes that i want to store on ListCommand.cs:

SqlCommand comm1 = new SqlCommand("SELECT Authors_Name FROM Author", SQLcon.conn);
                        SqlDataAdapter da1 = new SqlDataAdapter(comm1);
                        DataSet ds1 = new DataSet();
                        da1.Fill(ds1);
                        checkedListBox1.DataSource = ds1.Tables[0];
                        checkedListBox1.DisplayMember = "Authors_Name";
                        checkedListBox1.ValueMember = "Authors_Name";

Thank you to those who can help!

Are both of your classes forms? Is checkedListBox1 on AddBook form, and if so, is it that instance of checkedListBox1 you wish to rebind or do you have a second checkedListBox on the ListCommand class that you want to bind?

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.