Load database information into a textbox using the layers template with C#

Asked

Viewed 284 times

1

Good morning, everyone! I’m new enrolled in the forum, but I’ve been following them for some time, I’m finishing a college TCC in C# (Visual Studio 2017), and I’m having a hard time in the project I’m putting together, where the problem is: My project is in 4 layers (DAL, BLL, Model and User Interface); In the database, I have a table called "address", which contains the fields cep, street, neighborhood, city and Uf; In the "Customer Registration" screen, I need that when typing the ZIP code in a Maskedtextbox field, using the property "Leave" the same make a query in the database in the address table, and if there is a record the same return the data and fill in the due Textbox (street, district, city and Uf); If it is not in the database, it will make a query in the Web Service (THIS IS ALREADY WORKING).

Follow images of what I already have. EnderecosBLL EnderecosDAL Formulário de Clientes

If anyone can help me, I’d really appreciate it. Thank you!

  • Welcome Chris, avoid images, however in your case is advised to illustrate the problem. Also, keep the images, edit your question and put the codes to facilitate understanding.

1 answer

2


Chris_rodrigues, your query "Consultacep" is giving error, because it is VOID and has a Return...

Switch from VOID to Datatable, like this:

public DataTable ConsultaCep(string cep)
{
   DataTable tabela = new DataTable();
   NpgsqlDataAdapter da = new NpgsqlDataAdapter(...

   da.Fill(tabela);
   return tabelas;
}

Then you recover the ZIP code value inside the Query Datatable, as you do in the listing, but check BEFORE if the ZIP code has been returned, if it has not come, you will need the user to fill in the ZIP code). How will return only 1 record, will be something like this:

   strCEP = dt.rows[0]["CEP"].ToString()

See also:

Picking up column values from a Datatable

C# - Working with the Datatable object

Take datatable value and convert!

  • 1

    Thank you so much for your help Fabioln, it worked out what I wanted to do.

  • Valew Christian. Thanks for puncturing me!

Browser other questions tagged

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