select from 2 combobox and show data in textbox

0

I'm working on an application and getting stuck on something I do not know how to do it. What I want to do is the following but with Entity Framework without using Ado .

public void seleccionar_med()
{
    SqlConnection con1 = new SqlConnection("Data 
    Source=NBX\SQLEXPRESS;Initial Catalog=clinica;Integrated 
    Security=True");
    con1.Open();
    SqlCommand cmd = new SqlCommand("select * from medicamento where 
    id_medicamento = '" + cbmedicamento.SelectedValue + "' ", con1);
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.Read())
    {
        label9.Text = Convert.ToString(dr["stock"]);
        tbvencimiento.Text = Convert.ToString(dr["vencimiento"]);
        tbremito.Text = Convert.ToString(dr["remito"]);
        tblote.Text = Convert.ToString(dr["lote"]);
        label11.Text = Convert.ToString(dr["nombre"]);
        label9.Visible = true;

    }
    dr.Close();
    con1.Close();
}
    
asked by Ivan 27.10.2017 в 13:22
source

1 answer

0

To configure your entity framework: enter the description of the link here

Once you have your Entity Model, and using linq :

using (var context = new DatabaseEntities())
{
    var datos = select m from context.Medicamento
        where m.id_medicamento = cbmedicamento.SelectedValue
        select new {
              stock = m.stock,
              ..
        }
}
    
answered by 27.10.2017 в 23:08