jueves, 10 de noviembre de 2016

EJEMPLO RELLENAR UN LISTBOX DESDE UNA VISTA SQL

      rellenar_list_box("SincroSN", LstClte, "Cardcode");



 public void rellenar_list_box(string vista,ListBox namelist,string campo)/*Rellena los listbox de articulos, agentes y socios*/
        {
            sqlcon = new SqlConnection("server=localhost;Initial Catalog=principaBD;uid=VISTA;pwd=****");
            sqlcon.Open();
            string sQuery;
            sQuery = "SELECT * from "+vista+"";
            SqlCommand cmd;
            SqlDataReader dr;
            cmd = new SqlCommand(sQuery, sqlcon);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                namelist.Items.Add(dr[campo].ToString());
            }
            dr.Close();
            sqlcon.Close();
        }

1 comentario: