About Windows.Forms from C#

Asked

Viewed 45 times

0

I’m on a database replication project and I’m going through a problem.

When referencing a field that comes from a textbox it is bringing all the information from the textbox and not just the value that I entered into it. This is my code:

string conexao = "Server=localhost;port=5432;User Id="+db.Usuario.ToString()+";Password="+db.Senha.ToString() + ";Database="+db.Banco.ToString();

Follow picture.

inserir a descrição da imagem aqui

How can I resolve this so that only the text inside the textbox appears? Thanks for your help.

2 answers

1


You need to use the property Text to obtain the value entered in the Textbox. Using the method ToString(), unless it has been implemented differently in the object, you will always get the full name of the type.

Your code should look like this:

string conexao = "Server=localhost;port=5432"
                + ";User Id=" + db.Usuario.Text
                + ";Password=" + db.Senha.Text 
                + ";Database=" + db.Banco.Text;
  • So, I’ve tried this before but . Text is in red. https://prnt.sc/q8wo19

  • Post the file part .Designer.Cs to know what your property is about db

  • Sorry, I just saw the image now. Post the code (or part of it) of the class Database

  • DEAR ONES, THANK YOU SO MUCH FOR YOUR HELP. I FOUND MY MISTAKE.

  • 1

    The part where I get the data, I was treating it wrong. private void passwordOrigem_TextChanged(Object Sender, Eventargs and) { bank.Password = passwordOrigem.Text; }

0

The answer from the friend above was correct. I got lost when it came to capturing the information.

private void UsuarioDestino_TextChanged(object sender, EventArgs e)
    {
        bancoDestino.Usuario = sender.ToString();
    }

But the right way is how the friend spoke:

private void UsuarioDestino_TextChanged(object sender, EventArgs e)
    {
        bancoDestino.Usuario = UsuarioDestino.Text;
    }

Thanks for all your help.

Browser other questions tagged

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