1
I’m trying to list the payment methods of the table dbo.FormaPgto
in a Combobox but you’re making that mistake.
Follows code.
Class:
public List<Formas_Pagamento> ListarFormaPgto(string campos = "*")
{
try
{
List<SqlParameter> listaParam = new List<SqlParameter>();
Formas_Pagamento objFormaPgto = new Formas_Pagamento();
strSQL = new StringBuilder();
strSQL.Append("SELECT " + campos + " FROM FormaPagto WHERE 1=1");
strSQL.Append(" AND FPEmpresa = @CodEmpresa");
listaParam.Add(new SqlParameter("@CodEmpresa", FPEmpresa));
if (FPCodigo > 0)
{
strSQL.Append(" AND FPCodigo = @FPCodigo");
listaParam.Add(new SqlParameter("@FPCodigo", FPCodigo));
}
if (!string.IsNullOrEmpty(FPDescricao))
{
strSQL.Append(" AND FPDescricao LIKE @FPDescricao");
listaParam.Add(new SqlParameter("@FPDescricao", "%" + FPDescricao + "%"));
}
DataTable dtFP = SqlDAO.consultarSQL(strSQL, listaParam.ToArray());
return dtFP.ToList<Formas_Pagamento>();
}
catch (Exception)
{
throw;
}
}
}
}
Method:
protected void CarregarDDLFormaPagto()
{
try
{
Formas_Pagamento objFP = new Formas_Pagamento();
objFP.FPEmpresa = Metodos.empresa;
List<Formas_Pagamento> listaFP = objFP.ListarFormaPgto();
cbxFormaPgto.DataSource = listaFP;
cbxFormaPgto.DisplayMember = "FPDescricao";
cbxFormaPgto.ValueMember = "FPCodigo";
cbxFormaPgto.Enabled = true;
}
catch (Exception ex)
{
throw ex;
}
}