Hello! My scenario is as follows:
I'm developing a web application in C # ASP.NET, and I'm having some difficulties getting the database's data (via LINQ to SQL) to the page controls.
Below is one of the controls in my .aspx
where I want to bring a certain information from the bank
<asp:TextBox
ID="txtCodigo"
ClientIDMode="Static"
CssClass="form-control"
MaxLength="4"
Enabled="false"
runat="server">
</asp:TextBox>
And below my .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 ClienteBusiness.ListarCliente(idCliente)
method calls another method which, in turn, queries the database, 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;
}