-->

Tuesday, March 3, 2015

How to bind label and text box control using edmx file in windows form c#

How to bind label and text box control using edmx file in windows form c#

In previous article we have already learn about bind label or text box using ado.net. Today, i will discuss about edmx file. If you want to bind label or text box in windows form, edmx file is the best solution for this type of problem. There are following steps to bind the label or text box:

I am giving you a whole code video for user friendly: 

  1. First to add some label and text boxes in the form Like:
How to bind label and text box control using edmx file in windows form c#

  1.  Now, add edmx file in the solution
  2. Now, copy this code and paste in the button click event handler block.

 private void button1_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(idtxt.Text);
            Student_DBEntities dc = new Student_DBEntities();
            var getrecord = dc.Student_record.Where(a => a.Id == id).SingleOrDefault();

            Studentidtxt.Text = getrecord.Student_Id;
            studentnametxt.Text = getrecord.Student_Name;
            fathernametxt.Text = getrecord.Father_Name;
            MotherNametxt.Text = getrecord.Mother_Name;
            Addresstxt.Text = getrecord.Address;

        }
Here,
  1. Student_DBEntities is a data context name, Create a object of that class, Access public property(Student_record -Screen Shot mentioned in the link) by using instance name.
  2. Access single record with the help of where clause with lambda expression also use SingleOrDefault( ) method.
  3. By using getrecord variable you can access table fields or you can say model class fields. 
  4. Get each fields which is required by you, returning result assign in Text boxes.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved