从LIST<>中检索值

时间:2016-12-28 21:56:48

标签: c# asp.net list

我从列表中检索数据时遇到问题,我必须获取每个选定记录的信息,我可以这样做,但我将这些数据放在列表中<>我需要在文本框中,我在我的应用程序中有工作类,这是我的数据层:

public List<Cajas> cajas_upd_cons_caja_detalle(string clienteCodigo, string cajaCodigo, int cajaNumero)
{
    List<Cajas> ListCaj_x_Cod_CajNum = new List<Cajas>();
    string storedProcedure = "CAJAS_UPD_CONS_CAJA_DETALLE"; //stored procedure

    using (DbConnection con = dpf.CreateConnection())
    {
        con.ConnectionString = conStr;
        using (DbCommand cmd = dpf.CreateCommand())
        {
            cmd.Connection = con;
            cmd.CommandText = storedProcedure;
            cmd.CommandType = CommandType.StoredProcedure;

            DbParameter param1 = cmd.CreateParameter();
            param1.DbType = DbType.String;
            param1.ParameterName = "CLIENTE_CODIGO"; //param
            param1.Value = clienteCodigo.Replace(" ", ""); 
            cmd.Parameters.Add(param1);

            DbParameter param2 = cmd.CreateParameter();
            param2.DbType = DbType.String;
            param2.ParameterName = "CAJA_CODIGO"; //param
            param2.Value = cajaCodigo.Replace(" ", "");
            cmd.Parameters.Add(param2);

            DbParameter param3 = cmd.CreateParameter();
            param3.DbType = DbType.String;
            param3.ParameterName = "CAJA_NUMERO"; //param
            param3.Value = cajaNumero;
            cmd.Parameters.Add(param3);

            con.Open();
            cmd.ExecuteNonQuery();
            using (DbDataReader dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    try
                    {
                        //THIS IS MY CLASS
                        Cajas caja = new Cajas(); //

                        caja.CajaContenido = dr["CONTENIDO"].ToString();
                        caja.CajaEstado = dr["EST"].ToString();
                        caja.FecEmisionDoc = Convert.ToDateTime(dr["EMISION"].ToString());
                        caja.FecCaducidDoc = Convert.ToDateTime(dr["CADUCIDAD"].ToString());
                        caja.CajaUbi1 = dr["UBI1"].ToString();
                        caja.CajaUbi2 = dr["UBI2"].ToString();
                       ListCaj_x_Cod_CajNum.Add(caja);
                    }
                    catch (System.InvalidCastException)
                    { }
                }
            }
        }
    }
    return ListCaj_x_Cod_CajNum;
}

这是我的演讲课:

protected void Page_Load(object sender, EventArgs e)
{
    UpdCadDet_limpiarCampos();
    if (!IsPostBack)
    {
        clienteCodigo = Request.QueryString["cliCod"];
        cajaCodigo = Request.QueryString["cajCod"];
        cajaNumero = Request.QueryString["cajNum"];
        lblUpdCajDet_CliCod.Text = clienteCodigo;
        lblUpdCajDet_CajCod.Text = cajaCodigo;
        lblUpdCajDet_CajNum.Text = cajaNumero;

        //this is only for testing
        List<Cajas> cajastest = cajaUpd_BL.cajas_upd_cons_caja_detalle (clienteCodigo, cajaCodigo, Convert.ToInt32(cajaNumero));

    }
}

如果调试应用程序我可以看到从数据库中检索到的值,但我的问题是如何在我的表示类中(在GUI中)获取它们。

我希望有人可以帮助我。

最好的问候

1 个答案:

答案 0 :(得分:0)

由于 我可以得到列表值:

List<Cajas> cajadetalle = cajaUpd_BL.cajas_upd_cons_caja_detalle
            (clienteCodigo, cajaCodigo, Convert.ToInt32(cajaNumero));

        txtUpdCajDet_CajCon.Text = cajadetalle[0].CajaContenido.ToString();
        txtUpdCajDet_CajEst.Text = cajadetalle[0].CajaEstado.ToString();
        txtUpdCajDet_CajFem.Text = cajadetalle[0].FecEmisionDoc.ToString();
        txtUpdCajDet_CajFca.Text = cajadetalle[0].FecCaducidDoc.ToString();
        txtUpdCajDet_CajFal.Text = cajadetalle[0].AltaFecha.ToString();
        txtUpdCajDet_CajFba.Text = cajadetalle[0].BajaFecha.ToString();
        txtUpdCajDet_CajUb1.Text = cajadetalle[0].CajaUbi1.ToString();
        ......
        ......

所以我可以在文本框中获取值