0
How to select a die from my table column and display it in a label?
EX:
id = 10 -> Banana
Select * From tabela where id = 10
label.Text = Banana
MySqlConnection conexao = new MySqlConnection();
conexao.ConnectionString = ("server=localhost; user id=root; pwd=root ;database=semi");
conexao.Open();
MySqlCommand command = new MySqlCommand();
command.Connection = conexao;
command.CommandText = "Select Valor_Venda from produtos where Codigo = '" + comboBox4.Text + "'";
MySqlDataReader dr = command.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
label20.Text = dr;
I found an example on the internet and tried to adapt more I believe I’m not on the right path. Can you help me? Any doubt of my question comment that I answer.
When making a query in the database involving some kind of parameters it is important to use the parameters
@param
pq will help you and prevent SQL Injection attacks.– gato
I took his code and just added a few things, I didn’t modify. I also prefer to use parameters, but I didn’t know that it prevented attacks in this way, how does it work? You have a link explaining about this?
– Francisco
You can consult about SQL Injection here. And here is more information regarding the use of parameters in C#.
– gato