DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

ADO.NET Entity Framework

by Farooq Kaiser 6. June 2009 15:44
In this tutorial I will show you how you can create data access classes using the Microsoft Entity Framework when building an ASP.NET application. 
This tutorial will use AdventureWorks database. Follow the these steps.
  1. Add a new item to the project by right-clicking on WindowsFormsApplication1 in the Solution Explorer, clicking Add, and then clicking New Item.
  2. Select ADO.NET Entity Data Model from the Templates list and click ADD
  3. On the Choose Model Contents page, select the Generate from Database option and click Next.
  4. Set up as a database connection in Visual Studio, click New Connection to open the Connection Properties dialog and create a new connection to the database.
  5. On the Choose Your Database Objects page, expand the Tables node and check the contact table.
  6. Click Finish.
  7. Add the datagridview and a button on the form1.cs
  8. The following code will bind the grid with contact table.
    private void button1_Click(object sender, EventArgs e)
    {
    using (var context = new AdventureWorksEntities1())
    {
    dataGridView1.DataSource = context.Contact.ToList();
    }
    }

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

.NET | C# | SQL

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Jobs Autos Real estate Videos Power by Google