I am writing a database program with many forms. Is it better to declare the Sqlclient variables in 1 class that all forms will reference or do I want to keep doing this everytime I call a form:
Way I use to do it for each individual form.
SqlConnection cnn = Connection();
SqlCommand cmd = new SqlCommand("SELECT * from table1",cnn);
Right now I am doing this (Not sure if this is better or worse) Seems to be better to no redecclare a variable for the amount of forms that use the same variable. So this is what I have
public static SqlConnection cnn = new SqlConnection();
public static SqlCommand cmd = new SqlCommand();
then in all my forms i am doing this
Class1.cmd.connection = Class1.cnn;
Class1.cmd.commandtext = "Select * from table1";
Is this procedure ok or is it better the first way I suggested?