1
I cannot change customer information through ID
Code that makes the changes in the Database
public void Atualizar(Contato contato)//metodo para atualizar dados: update
{
OleDbParameter[] parametros = {
new OleDbParameter("CODIGO", contato.Codigo),
new OleDbParameter("NOME", contato.Nome),
new OleDbParameter("FONE", contato.Fone),
new OleDbParameter("EMAIL", contato.Email)
};
new ConexaoDAL().ConexaoAuto(parametros, "update Contato set NOME=@NOME,EMAIL=@EMAIL,FONE=@FONE where CODIGO=@CODIGO ", "Erro ao atualizar ");
}
Event Click page
public void SalvaDados()
{
try
{
if (SalvarCodigo == null)
{
Crud d = new Crud();
d.Gravar(new Contato(SalvarNome.Text, SalvarFone.Text, SalvarEmail.Text)); // gravando pessoa
Message.Text = "Cadastro salvo com sucesso";
}
else
{
int codigo = Convert.ToInt32(SalvarCodigo);
Crud d = new Crud();
d.Atualizar(new Contato(codigo, SalvarNome.Text, SalvarFone.Text, SalvarEmail.Text));
Message.Text = "Cadastro alterado com sucesso";
}
}
catch (Exception ex)
{
throw new Exception(Message.Text = ex.Message);
}
}
NOTE: when it gives the error it talks to convert, but I have tried to convert what is inside the textbox and even then it doesn’t work. aspx.
What’s the mistake? Where does it occur? In what situation? As I don’t know the problem, I don’t even know if what was posted is enough for us to help. The impression is that it is not. Take this
try-catch
that it is not doing anything useful there, otherwise it is caused problem.– Maniero
the error occurs when I enter in the code field the code to be changed it says it has to convert, but even if converting appears the same error.
– André Felipe Jardim Firmo
The first thing to do is take the
try-catch
as I told you to see the actual error, you are hiding it without solving it. Do not capture exception if you cannot solve the problems. Do not captureException
never, unless you know why you’re doing it. http://answall.com/search?q=user%3A101+%5Bexception%5D. Where are youSalvarCodigo
? I find this whole code very strange, there seems to be a general problem of design.– Maniero
I understand, already taking off Try-catch, Salvarcod is coming from the page, where I insert the customer’s Cod.
– André Felipe Jardim Firmo
But show him so we can help.
– Maniero