When I try to make a DELETE
the following message is displayed:
Mycode:
privatevoidBtnExcluir_Click(objectsender,EventArgse){if(MessageBox.Show("Confirma a Exclusão desses Registros?", "Atenção",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
conexao.ConnectionString = strconexao;
cmd.Connection = conexao;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "DELETE FROM PRODUTOS WHERE CODPROD =Codigo";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@Codigo", chaveID);
try
{
conexao.Open();
cmd.ExecuteNonQuery();
MessageBox.Show("Registros Excluidos com Sucesso!!!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Atenção");
}
finally
{
if (conexao.State == ConnectionState.Open)
{
conexao.Close();
MontarLista();
LimparFormulario();
BtnExcluir.Enabled = true;
}
}
}
}