1
I’m putting together a little system where I created a Formulario
where there is a Combobox
listing the names of the employees stored at the bank and a DataGrid
that shows the services done by them (value, description and client).
When selecting the employee in Combobox,I wanted to show the services done by him,
SELECT func_nome, serv_desc, serv_cliente, serv_valor FROM func_serv
INNER JOIN func_dados ON func_serv.func_id = func_dados.func_id
WHERE func_serv.func_id = //codigo da funcionaria;
My doubt is, when picking the index of the selected combobox, how can I use it as parameter for my sql query, replacing that commented part of the code.
I thought about creating several ifs, but if a new employee is created, I will have to put another if.
Help me out, please
How do you fill the Combobox? If you take the data directly from the database, you can use Combobox’s Displaymember and Valuemember properties and take the combo Selectedvalue with the selected ID.
– Julio Borges
conexao = new SqlConnection(conexao_sqlserver);
 SqlCommand sql = new SqlCommand("select func_nome from func_dados", conexao);
 SqlDataAdapter da = new SqlDataAdapter(sql);

 DataTable dt = new DataTable();

 da. Fill(dt); Try { for (int i = 0; i < dt.Rows.Count; i++) { cb_func_passbook.Items.Add(dt.Rows[i]["func_name"]); } } catch (Exception error) { throw error; }
– Lima Kewnantchy