2
I’m trying to update my database by visual Studio(c#), but the update is not being carried out I don’t know why.
Table script(sql developer
):
CREATE TABLE Login
(
Cod_login NUMBER(8) NOT NULL,
Usuario VARCHAR2(50) NOT NULL,
Senha VARCHAR2(50) NOT NULL,
cod_Nivel number(5)NOT NULL,
Status_Login CHAR(1) NOT NULL,
CONSTRAINT PK_Cod_login_Login PRIMARY KEY (Cod_login)
);
c update script#:
public void AlterarSenha(string usuario)
{
string strQuery;
strQuery = (" UPDATE Login ");
strQuery += (" SET ");
strQuery += ("senha = '" + _senha + "' ");
strQuery += (", Status_Login ='" + 1 + "'");
strQuery += (" WHERE ");
strQuery += (" usuario = '" + _usuario + "' ");
clnBancoDados ObjClnBancoDados = new clnBancoDados();
ObjClnBancoDados.ExecutaComando(strQuery);
}
public void Alterar()
{
if (txtnovasenha.Text == "")
{
MessageBox.Show("Digite Sua Nova Senha!");
}
if ((txtnovasenha.Text.Length < 4))
{
MessageBox.Show("A Senha Deve Conter no Mínimo 4 Digitos!");
}
if ((txtnovasenha.Text.Length > 8))
{
MessageBox.Show("A Senha Deve Conter no Máximo 8 Digitos!");
}
else
{
clnlogin login = new clnlogin();
login.Senha = txtnovasenha.Text;
login.AlterarSenha(txtLogin.Text);
MessageBox.Show("A Senha do Usuário "
+ txtLogin.Text + " foi Alterada com Sucesso para "
+ login.Senha + "!",
"Alteração", MessageBoxButtons.OK, MessageBoxIcon.Information);
It shows the message, but does not update. I tried to change several things but could not. I did something wrong?
This code is incomplete, right?
– Jéf Bueno
No.Only the save button was missing, which only calls the Change method();
– enzo
And that key missing in the first method?
– Jéf Bueno
tidy. I wobble my.
– enzo
strQuery += (", Status_Login ='" + 1 + "'");
tries to change here:strQuery += (", Status_Login ='" + 1.ToString() + "' ");
– guijob
I tried, it didn’t help.
– enzo
What is this component
clnBancoDados
?– Eric Wu
That’s where I connect to my bank.
– enzo
We need the contents of the Executacommand() method to be able to give you an answer, it is probably the source of the problem.
– Julio Borges
One remark: you are going the worst way to record a record in C#. Use the
SqlCommand
withparamentros
and have simple, easy-to-maintain code. Links that can help you https://msdn.microsoft.com/pt-br/library/system.data.sqlclient.sqlcommand.parameters(v=vs.110). aspx and http://www.devmedia.com.br/utilizando-parametros-no-sqlcommand-em-c/28440– novic
Put the code part of the method: Objclnbancodados.Run command(strQuery); to see how you are doing. may be missing an Execurenonquery() or a Savechanges, depending on your approach...
– JcSaint
I can even put, but I think that’s not it, because the other functions are working.
– enzo
if I comment the lines://strQuery += (" WHERE "); //strQuery += (" user = '" + _user + "' "); it works; but instead of updating only one row of my table, it updates all.
– enzo
The user you are trying to update exists in the table? It can only be that then
– Julio Borges
Yes, it does. It must be something silly.
– enzo