How to databind a texbox without assigning it a value?

Asked

Viewed 31 times

0

I have a txtEmail textbox in a Display() method where I assign you an email (via a query) so that I can display it in a user profile (all ok).

txtEmail.Text = item["email"].ToString();//devolve sapo.pt

But when I try to edit the value through the query, if I try to edit, always write me the value that had already been closed. any hints ?

SqlCommand cmd = new SqlCommand("UPDATE Utilizadores SET NomePessoal=@NomePessoal, nifPessoal=@nifPessoal, contacto=@contacto, email=@email WHERE (idLogin = @idLogin)", con);
        cmd.Parameters.AddWithValue("@email", txtEmail.Text); // escrevo hotmail.com, mas fica na mesma com o valor sapo.pt

I do Binding like this

//Seleção do perfil 
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow item in dt.Rows)
            {
                txtid.Text = item["idLogin"].ToString();
                txtNP.Text = item["NomePessoal"].ToString();
                txtUT.Text = item["Utilizador"].ToString();
                txtNif.Text = item["nifPessoal"].ToString();
                txtCon.Text = item["contacto"].ToString();
                txtTipo.Text = item["tipo"].ToString();
            }
        }
        else
  • When you add the SQL parameter the value that is assigned is not the one in the TextBox?

  • Supposedly yes , but as I above assign you a value query update with the value above and not the new one I wrote, I don’t know why

  • If you do debug what value is in control txtEmail?

  • The value is sapo.pt. I remove the action to the textbox above the Updtade works , only it does not display me (shows) the previous email (becomes empty the textbox)

  • To TextBox is associated with any BindingSource?

  • @Joãomartins edited above , that follows after the query

  • @Joãomartins some hint?

  • I’m still a little confused about how your code is... especially the code sequence. You can’t change the question and put the whole code (if it’s not too much)?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.