Violeta Popa

Violeta Popa

  • NA
  • 137
  • 164.4k

filling combobox with datatable

Apr 17 2013 1:18 PM
Hi :) I'm trying to fill a combobox with a datatable, but i don't know what's wrong, because it doesn't display any item. This is the code:

SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename='C:\\Users\\Vio\\Desktop\\Gestiune asigurari auto\\Gestiune asigurari auto\\Resources\\asigurari.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True";
            conn.Open();
      
            string selectClient = "SELECT * FROM client WHERE UPPER(SUBSTRING(denumire, 1, 2)) = 'RO' and tip_client='altul'";
            SqlDataAdapter da = new SqlDataAdapter(selectClient, conn);

            DataTable dt = new DataTable();
            da.Fill(dt);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                comboBox1.Items.Add(dt.Rows[i]["denumire"]);
            }

            conn.Close();

the connection works fine, i've tested it.

Answers (4)