public partial class Form1 : Form { private void StartApp() { LobGamma.LogInPanel.FillComboBox(LogInpanel_ComboBox, LobGamma.Connection.ObtainConnection()); } } public class LogInPanel { public static void FillComboBox(ComboBox Box, SqlConnection con) { Box.Items.Clear(); using (con) { SqlCommand com = new SqlCommand("Select Id From UsersTable", con); con.Open(); using (SqlDataReader reader = com.ExecuteReader()) { while (reader.Read()) { Box.Items.Add(reader["Id"].ToString()); } reader.Close(); } } con.Close(); } I want to know if I am going the right way about using a method from another class. I only need to use the method once. Is the way I have done it by using a static method acceptable? or should the method be non-static.
If the method should be non-static, Is it best to Inherit from IDisposable so that I can use the Class in a Using Statement? or would simply creating an instance of the class and waiting for GC be acceptable?
usingon anSqlConnectionwhich has been passed to the method as a parameter. This may not be a good idea, as you are disposing an instance you have been given from outside the method. This may surprise the caller. Consider moving theusingto theStartAppmethod or creating theSqlConnectioninsideFillComboBox.List<string>