0
I am creating a form that I would like it to work as follows: First the user would select the type of exercise that would be played in the Checked list box using a Combo Box, then the bank would return all the values found that matched that type of exercise (For example the user would choose Back in Combobox and appear all exercises for back in the Checked List Box).
I know how to display the values in a Data Grid, but by aesthetic and by the final functioning of the form I prefer not to use Data Grid.
Conexao.Conectar();
string sql = @"select Exer_NM from Exercicios
Where Exer_Tipo = @Exer_Tipo";
SqlCommand cmd = new SqlCommand(sql, Conexao.conn);
cmd.Parameters.AddWithValue("Exer_Tipo", cboTipo.Text);
// Armazena o resultado do comando SELECT
SqlDataReader dr = cmd.ExecuteReader();
//Laço de repetição para retornar todos os valores
// dr.Read() - Lê uma nova linha
while (dr.Read())
{
// Mostra no listBox os dados retornados
clb.Items.Add(dr[1].ToString());
}
Conexao.Desconectar();
My biggest doubts are:
1 - In the code I tried to mount, if I am using the correct event (Combobox Selected Index Changed or should use Text Changed for example.
2 - If it is correct to assign the parameter "Exer_type" to the cboTipo.text.
3 - And if there is some gigantic mistake in my code.
(I am using Sql Server 2017, I posted the image code because I am not used to formatting site text yet, I apologize if this makes understanding difficult).
put the code in the question instead of an image
– Ricardo Pontual
Even if you don’t know how to format the code on the site, insert it instead of the image, someone will format it for you.
– Focos
Okay, I added the code. I used a code to add the values found in Select to a listbox.
– Bruno Moraes