0
Hello! My scenario is as follows:
I am developing a web application in C# ASP.NET, and I am having some difficulties to bring the database data (via LINQ to SQL) to the page controls.
Below one of the controls of my file .aspx
where I wish to bring a certain bank information
<asp:TextBox
ID="txtCodigo"
ClientIDMode="Static"
CssClass="form-control"
MaxLength="4"
Enabled="false"
runat="server">
</asp:TextBox>
And down with mine .aspx.cs
.
protected void Page_Load(object sender, EventArgs e)
{
int idCliente;
TB_CLIENTE_CLI cliente = new TB_CLIENTE_CLI();
if (Int32.TryParse(Request.QueryString["ID"], out idCliente))
{
ClienteBusiness.ListarCliente(idCliente);
txtCodigo.Text = cliente.ID_CLIENTE_CLI.ToString();
txtRazaoSocial.Text = cliente.TXT_RAZAOSOCIAL_CLI;
txtNomeFantasia.Text = cliente.TXT_NOMEFANTASIA_CLI;
txtCNPJ.Text = cliente.TXT_CNPJ_CLI;
txtCEP.Text = cliente.TXT_CEP_CLI;
txtLogradouro.Text = cliente.TXT_LOGRADOURO_CLI;
}
}
My application is divided into layers. The method ClienteBusiness.ListarCliente(idCliente)
calls another method that, in turn, makes the query to the bank, as shown in the code below:
public static List<TB_CLIENTE_CLI> ListarCliente(int idCliente)
{
List<TB_CLIENTE_CLI> cliente = null;
using (PlanoTesteDataContext context = new PlanoTesteDataContext())
{
cliente = (from clientes in context.TB_CLIENTE_CLIs
where clientes.ID_CLIENTE_CLI == idCliente
select clientes).ToList();
}
return cliente;
}
Are you experiencing what difficulty specifically? The method is returning some exception at some point?
– Pedro Lorentz
Hello Peter! The data just isn’t displayed. I don’t get any Exception or error.
– Victor Alencar Santos
"Debugging" the code you checked if you are entering the if and values are being displayed? If yes, you can go "debugging" by placing it in the Visual Studio Watch window to see if at any point in the request flow this value is deleted.
– Pedro Lorentz
Pedro, there were some errors in my methods, which Eduardo listed and so I was able to solve the problem. Still, thank you for your help!
– Victor Alencar Santos