4
I have this function that has a simple registration but is not registering
My doubt would be on that return RES;
which gives the error message below the code.
//botao para cadastrar OS
private void Button1_Click(object sender, EventArgs e)
{
bool res = false;
try
{
SqlCommand query =
new SqlCommand("INSERTO INTO gerarOS VALUES (@codOS,@nomeCliente, @modeloMoto, @quilometragem, @dataOS)");
query.Parameters.AddWithValue("@nomeOS", codOS);
query.Parameters.AddWithValue("@nomeCliente", nomeCliente);
query.Parameters.AddWithValue("@nomeOS", modeloMoto);
query.Parameters.AddWithValue("@nomeOS", quilometragem);
query.Parameters.AddWithValue("@nomeOS", dataOS);
query.ExecuteNonQuery();
}
catch (Exception ex)
{
//caso der erro na inserção
res = false;
}
if (conexao.State == ConnectionState.Open)
conexao.Close(); // fecha conexão
return res;
}
Gravity Code Description Project File Line Deletion State CS0127 Error Like "Geraros.Button1_click(Object, Eventargs)" returns void, a Return keyword should not be followed by an expression of Object Projectproject D: Programming Projectproject Geraros.cs66Ativo
Two things: 1 - Where is the code that opens the connection because without it I can’t fix the problem with the
SqlCommand
that does not save. 2 - Take the linereturn res
forButton1_Click
is void.– Augusto Vasques