Insert Data Using EDMF Onto Cloud Database With Azure

Introduction
 
Today, in this article let's play around with one of the interesting and most useful concepts in Azure.
 
Question: What is insert data to cloud database using Azure?
 
In simple terms "It enables insertion of data into a cloud database and maintainance with the help of Azure".
 
Step 1: Create a cloud database named "Company"

Create-a-cloud-database-in-WindowAzure.jpg 

Step 2: With the help of manage URL navigate to a specific server page
 
Manage URL: etc6zpqnyc.database.windows.net
 
Step 3: The company database showing up in the database server page

Create-a-Server-WebPage-in-WindowAzure.jpg

Step 4: Create an employee table. The design mode of the employee table looks like this:

table-in-WindowAzure.jpg

Step 5: Insert some data into the table

table-Before-insert-data-in-WindowAzure.jpg

Step 6: Open Visual Studio 2010 and create an "ASP.NET Web Forms Application", as in:

Open-visual-studio-2010.jpg

Step 7: Add an EDMF item to the project

Add-EDMF-item-to-visual-studio-2010.jpg

Step 8: Choose generate from database and click the "Next" button

generate-from-database-in-visual-studio-2010.jpg

Step 9: Add new connection

Add-new-connection-in-visual-studio-2010.jpg

Step 10: Give the necessary server details for the connection and click on ok

server-details-for-connection-in-visual-studio-2010.jpg

Step 11: Connection is established and click the "Next" button

connection-established-in-database.jpg 

Step 12: Choose the required table and click the "Finish" button

Choose-table-from-database.jpg 

Step 13: An EDMF is created and the design of the data looks like this:

EDMF-created-in-visual-studio-2010.jpg

Step 14: The complete code of Default.aspx looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="InsertDataEFAzureApp._Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <center>

        <div>

            <table>

                <tr>

                    <td colspan="2">

                        <asp:Label ID="Label1" runat="server" Text="Insert Data to Cloud Database - Azure App"

                            Font-Bold="true" Font-Size="Large" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td>

                        <asp:Label ID="Label3" runat="server" Text="Please Enter First Name" Font-Size="Large"

                            Font-Names="Verdana" Font-Italic="true"></asp:Label>

                    </td>

                    <td>

                        <asp:TextBox ID="TextBox2" runat="server" Width="120px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td>

                        <asp:Label ID="Label2" runat="server" Text="Please Enter Last Name" Font-Size="Large"

                            Font-Names="Verdana" Font-Italic="true"></asp:Label>

                    </td>

                    <td>

                        <asp:TextBox ID="TextBox1" runat="server" Width="120px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td>

                        <asp:Label ID="Label4" runat="server" Text="Please Enter Age" Font-Size="Large" Font-Names="Verdana"

                            Font-Italic="true"></asp:Label>

                    </td>

                    <td>

                        <asp:TextBox ID="TextBox3" runat="server" Width="120px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td colspan="2" align="center">

                        <asp:Button ID="Button1" runat="server" Text="Insert Data to Cloud" Font-Names="Verdana"

                            Width="213px" BackColor="Orange" Font-Bold="True" OnClick="Button1_Click" />

                    </td>

                </tr>

                <tr>

                    <td colspan="2" align="center">

                        <asp:Label ID="Label5" runat="server" Font-Bold="true" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>

                    </td>

                </tr>

            </table>

        </div>

    </center>

    </form>

</body>

</html>


Step 15: The complete code of default.aspx.cs looks like this:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace InsertDataEFAzureApp

{

    public partial class _Default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            this.TextBox2.Focus();

        }

        protected void Button1_Click(object sender, EventArgs e)

        {

            if (string.IsNullOrEmpty(TextBox1.Text) || string.IsNullOrEmpty(TextBox2.Text) || string.IsNullOrEmpty(TextBox3.Text))

            {

                Label5.Text = "Please Enter Some Values";

                Label5.ForeColor = System.Drawing.Color.Red;

            }

            else

            {

                CompanyEntities objCompany = new CompanyEntities();

                objCompany.AddToEmployee(new Employee

                {

                    FirstName = TextBox2.Text,

                    LastName = TextBox1.Text,

                    Age = int.Parse(TextBox3.Text)

                }

                );

                objCompany.SaveChanges();

                Label5.Text = "Data Inserted Successfully";

                Label5.ForeColor = System.Drawing.Color.Green;

                TextBox1.Text = string.Empty;

                TextBox2.Text = string.Empty;

                TextBox3.Text = string.Empty;

            }

        }

    }

}


Step 16: The output of the application looks like this:


Insert-Data-To-CloudData-in-WindowAzure.jpg


Step 17: The output of the table data before inserting the application looks like this:


table-Before-insert-data-in-WindowAzure.jpg 


Step 18: Data entering output of the application looks like this:


Data-Entering-output-windowAzure-App.jpg


Step 19: Inserted data showing on the cloud output of the application looks like this:


table-After-inserted-data-in-WindowAzure.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all
    MVC Corporation is consulting and IT services based company.