---
title: "Insert, Update, Delete in Windows Azure Application"  
description: "In this article I am going to explain how to perform insert, update, delete and select data using ADO.NET Entity Framework in a Windows Azure applicat"  
author: "Chris Anderson"  
published: 2012-01-23  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/867/insert-update-delete-in-windows-azure-application  
category: "cloud computing"  
tags: ["cloud computing"]  
reading_time: 4 minutes  

---

# Insert, Update, Delete in Windows Azure Application

In this article I am going to explain how to perform insert, update, delete and select [data](https://www.mindstick.com/articles/326933/5-reasons-big-data-is-important-to-the-logistics-industry) using ADO.NET Entity Framework in a Windows Azure application.\

· Open Microsoft Visual Studio 2010 as an administrator.

· To create a new project **File** – **New** – **Project**.

· Select **Cloud** template from the **Installed Templates**.

· Select **Windows Azure Project** and enter the name of the project as **DataOperation**.

· Click **OK** to proceed.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/cf912728-7cd2-4f15-9da6-ad47a5204978.png)

· To add an asp.net web role to the solution, choose **ASP.NET** **Web Role** and then choose the right arrow. The roles are displayed in the **Windows Azure solution** pane of the dialog box. You can rename it as DataOperation.

· Click OK to add.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/df50a61f-58d2-45d8-8577-b78a4b8eaf7f.png)

After adding web role, delete all the files from the DataOperation web role in the solution explorer except **References**, **Properties**, **and WebRole.cs**.

· Add a web form (**Default.aspx**) in a web role.

· Add a new **web.config** file.

Modify the **Default.aspx** as shown below:

```
   <div>        <table border="1" align="center">            <tr><td>                <table cellpadding="10" cellspacing="10">                   <tr>                      <td align="right">                          <asp:Label ID="lblId" runat="server" Text="Employee ID:"> 
                          </
                          </asp:Label>                       </td>                       <td>                          <asp:TextBox ID="txtId" runat="server"></asp:TextBox>                       </td>                    </tr>                    <tr>                       <td align="right">                          <asp:Label ID="lblName" runat="server" Text="Name :" >  
                          </
                          </asp:Label>                        </td>                        <td>                           <asp:TextBox ID="txtName" runat="server"></asp:TextBox>                        </td>                    </tr>                    <tr>                       <td colspan="2" align="center">                         <asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" />                         <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />                         <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />                       </td>                     </tr>                     <tr>                       <td colspan="2" align="center">                          <asp:GridView ID="gridEmpData" runat="server" CellPadding="10" ForeColor="#333333" GridLines="None">                               <AlternatingRowStyle BackColor="White" />                               <EditRowStyle BackColor="#2461BF" />                               <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />                               <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />                               <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />                                <RowStyle BackColor="#EFF3FB" />                     
                              <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />                                <SortedAscendingCellStyle BackColor="#F5F7FB" />                                <SortedAscendingHeaderStyle BackColor="#6D95E1" />                                <SortedDescendingCellStyle BackColor="#E9EBEF" />                                <SortedDescendingHeaderStyle BackColor="#4870BE" />       
                  </asp:GridView>                       </td>                     </tr>                </table>            </td></tr>        </table>  </div>
```

Now you have to create an **ADO.NET Entity Data Model**:

· Right click on web role (Data Operation) in the solution explorer.

· Select **Add** – **New Item**.

· Select **Data** template from the **Installed Templates**.

· Select **ADO.NET Entity Data Model** and enter the name of the model.

· Click **Add**

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/8f43cdd5-c3ea-47c7-9fac-ab87ee8a0ec1.png)

In the next window ((**Entity Data Model Wizard**), select **Generate from database** and click **Next**.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/124c2774-31dd-4daf-b72c-ec35999039a1.png)

Then fill the connection string properties (Server Name, User Name, Password and Database name) in the **Connection Properties** window and click OK.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/d405eddd-f8c7-45b2-9931-6e3f00ea8549.png)

When you click on OK, **Entity Data Model Wizard** will open. Enter the entity connection names as **CloudEntities** and click on **Next** button.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/55341df4-47d9-4ffe-bd35-afdc5f2c9f01.png)

Select a table that you want to select. Here I am selecting an Employee table contains two columns i.e. **Id (int)** and **Name (string)**.

Enter the model namespace as **AzureModel** and click on Finish button.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/56af2bf2-81d6-4756-a1fb-d96b9c917ccd.png)

When you click on the **Finish** button, the structure of the model should something like below:

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/72e4f3f3-b37e-4eea-8f6b-6da665464a02.png)

Now in the code behind of the Default.aspx (**Default.aspx.cs),** add the following code in order perform the insert, update, delete and select operation:

```
 protected void Page_Load(object sender, EventArgs e)        {            //display all the record present in the database first time on page load            if (!Page.IsPostBack)                RefreshGrid();        }       //display the current data from database table in a gridviewprivate void RefreshGrid()        {            GridView gridData = gridEmpData;            gridData.AutoGenerateColumns= false;            gridData.Columns.Clear();            gridData.Columns.Add(new BoundField()
         { HeaderText = "Id",
          DataField = "Id" 
         });            gridData.Columns.Add(new BoundField()
         { HeaderText = "Name",DataField = "Name" });            CloudEntities entities = new CloudEntities();            gridData.DataSource= entities.Employee.ToList();            gridData.DataBind();        }         //insert an employee record in the table        protected void btnInsert_Click(object sender, EventArgs e)        {            CloudEntities entities = new CloudEntities();            Employee emp = new Employee();            emp.Id = Convert.ToInt32(txtId.Text);            emp.Name = txtName.Text;            entities.AddToEmployee(emp);            entities.SaveChanges();            RefreshGrid();        }                //update a name of the employee in the table on the basis        // of id entered in the textbox        protected void btnUpdate_Click(object sender, EventArgs e)        {            CloudEntities entities = new CloudEntities();            int empId = Convert.ToInt32(txtId.Text);            Employee employee = entities.Employee.Where(emp => emp.Id == empId).FirstOrDefault();            if (employee != null)                employee.Name = txtName.Text;            entities.SaveChanges();            RefreshGrid();        }                //delete a record from the table on the basis of id        //entered in the textbox        protected void btnDelete_Click(object sender, EventArgs e)        {            CloudEntities entities = new CloudEntities();            int empId = Convert.ToInt32(txtId.Text);            Employee employee = entities.Employee.Where(emp => emp.Id ==  empId).FirstOrDefault();            if (employee != null)                entities.DeleteObject(employee);            entities.SaveChanges();            RefreshGrid();        }
```

Now press F5 to run an application. The output window should something like below. Enter an Id and Name and click on Insert button. It will insert a record in the database and display all the records in the gridview.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/d4d8682e-b82c-4d29-8197-07aa991431f0.png)

Now enter the Id of an existing employee and update his or her name in the textbox and click on Update. It will update a record if the id is exists in the database and display in gridview.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/b702334d-ae8f-418a-a96a-2ba0de979b94.png)

Now again enter the id of an existing employee in the textbox and click on delete button in order the delete the record from the database of an existing employee and from the gridview.

![Insert, Update, Delete in Windows Azure Application](https://www.mindstick.com/mindstickarticle/106add7e-1856-4030-b101-718035954dbb/images/b514b5d4-dde1-452f-9419-f4c2bdb66fa7.png)

I think after reading this article you can easily perform insert, update, delete and select command in any windows azure application by using ADO.NET Entity Model.

If you want to use SQL Azure management portal to perform insert, update, delete and select, change connection string in the web.config and provide connection string of SQL Azure.

\

---

Original Source: https://www.mindstick.com/articles/867/insert-update-delete-in-windows-azure-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
