0
I need to create a method, that when the user logs into the system, when the initial menu is loaded, it loads a Static DataTable, so that I can use the DataTable, for some popular ComboBox, without having to make several connections to my database.
So I created a Static class:
public static class Paises
{
    private static DataTable _tablePais;
    public static DataTable Tablepais
    {
        get { return Paises._tablePais; }
        set { Paises._tablePais = value; }
    }
}
I also created a class, to connect to my database:
 class Consulta_pais
{
    conexao_bd conexao = new conexao_bd();
    public void consulta()
    {
        conexao.bd_string();
        SqlConnection sqlconn = new SqlConnection(conexao.sqlconn);
        try
        {
            conexao._sql = @"SELECT code,descricao FROM Paises";
            SqlCommand cmd = new SqlCommand(conexao._sql, sqlconn);
            sqlconn.Open();
            Paises.Tablepais.Load(cmd.ExecuteReader());
        }
        catch
        {
        }
        finally
        {
            sqlconn.Close();
        }
    }
}
And then in the initial menu load, I call my class to bring the information from the bank:
 private void Menu_Inicial_Load(object sender, EventArgs e)
    {
        Consulta_pais load_pais = new Consulta_pais();
        load_pais.consulta();
    }
However, when I use to popular a combobox, the same goes blank, I’m populating the combobox so:
 private void carrega_cb_pais()
    {
        comboBox5.DataSource = Paises.Tablepais;
        comboBox5.ValueMember = "code";
        comboBox5.DisplayMember = "descricao";
    }