-1
I’m trying to execute a code every time, where it takes the value sent by the COM port of the Arduino, prints in a textbox and soon after generates an Insert in the mysql database.
Only that he read what was sent through the COM port and does not execute the Insert. Help me.
private void timer1_Tick_1(object sender, EventArgs e)
{
serialPort1.Open();
string entrada = serialPort1.ReadLine();
serialPort1.Close();
txtIDTag.Text = entrada;
if (txtIDTag.Text == "Gol")
{
string sql = "insert into tcc (Carro,Placa,Fabricante,Ano,Cor,Status,Data) value ('" + txtIDTag.Text + "','SCD - 4365','VW','2010','PRETO','NOVO', NOW())";
comando.CommandText = sql;
conexao.Open();
comando.ExecuteNonQuery();
conexao.Close();
MessageBox.Show("Dados cadastrados com sucesso.");
txtIDTag.Text = "";
}}
I tried to get the IF so he executed.
Why doesn’t it run? Because the text is different from Gol, because it can’t connect to the bank or because it is an error?
– Reginaldo Rigo
I have already tested the two tags I have. The one that is as goal and the other that define as Palio. The problem is that not Insert with either.
– Jon
But in the textbox appears correctly? What appears? Are you sure there are no extra characters in the string? Why not if using the value of
entrada
?– Woss
This is correct yes. I did what colleague Rodrigo said. Put the different sign and he executed correctly. I can not explain the reason. Would anyone have any opinion on how to correct?
– Jon
It’s not doing right no. ta jumping the if and executing what’s inside. I put two ifs now and it just executes what’s inside by jumping the if’s.
– Jon