1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

C# Fill combo box from SQL DataTable

Discussão em 'Outras Linguagens' iniciado por Stack, Janeiro 27, 2021.

  1. Stack

    Stack Membro Participativo

    DataTable _dt = new DataTable();

    using (SqlConnection _cs = new SqlConnection("Data Source=COMNAME; Initial Catalog=DATABASE; Integrated Security=True"))
    {
    string _query = "SELECT * FROM Doctor";
    SqlCommand _cmd = new SqlCommand(_query, _cs);

    using (SqlDataAdapter _da = new SqlDataAdapter(_cmd))
    {
    _da.Fill(_dt);
    }
    }
    cbDoctor.DataSource = _dt;
    foreach(DataRow _dr in _dt.Rows)
    {
    cbDoctor.Items.Add(_dr["name"].ToString());
    }


    There was an Error...

    The result is System.Data.DataRowView instead of data from database..

    Continue reading...

Compartilhe esta Página