Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
#ASP.NET 88
#DOTNET 87
BRH 79
ASP.NET 72
#.NET 52
C#.NET 48
DOTNET 47
ASP.NET 4.0 31
ASP.NET MVC 29
VisualStudio 27

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
May 2012 8
February 2013 7
January 2013 7

Insert with Dapper Micro ORM and ASP.NET MVC 3

May 19 2011 7:00PM by Jalpesh   

As I have already posted about the how to fetch data in my earlier post for Dapper ORM. In this post I am going to explain how we can insert data with the dapper ORM. So let’s extend the earlier post project. As explained in earlier post I have already created a class called CustomerDB this class will contains all the operation with Dapper Micro ORM. So For inserting data let’s first create CREATE method like following in CutomerDB Class like following. In that I have create a simple Insert Query in string and then using connection.execute method to execute method. Following is code for that.

public class CustomerDB
{
    public string Connectionstring = @"Data Source=DotNetJalps\SQLExpress;Initial Catalog=CodeBase;Integrated Security=True";

    public IEnumerable<Customer> GetCustomers()
    {
        using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
        {
            sqlConnection.Open();
            var customer = sqlConnection.Query<Customer>("Select * from Customer");
            return customer;

        }
    }

   
    public string  Create(Customer customerEntity)
    {
        try
        {
            using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
            {
                sqlConnection.Open();
               
                string sqlQuery = "INSERT INTO [dbo].[Customer]([FirstName],[LastName],[Address],[City]) VALUES (@FirstName,@LastName,@Address,@City)";
                sqlConnection.Execute(sqlQuery,
                                      new
                                          {
                                              customerEntity.FirstName,
                                              customerEntity.LastName,
                                              customerEntity.Address,
                                              customerEntity.City
                                          });

                               sqlConnection.Close();

            }
            return "Created";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }

    }

}

 

Now we are ready with Create Method for database now let’s create two ActionResult for the Creating customer like following in Customer Controller like following.

public ActionResult Create()
{
    return View();
}

//
// POST: /Customer/Create

[HttpPost]
public ActionResult Create(Customer customer)
{
    try
    {
        // TODO: Add insert logic here
        var customerEntities = new CustomerDB();
        customerEntities.Create(customer);
        return RedirectToAction("Index");
    }
    catch
    {
        return View();
    }
}

Now we are ready with the both ActionResult. First ActionResult will return simple view of Create which we are going to create now and another ActionResult Create will get customer object from the form submitted and will call our create method of CustomerDB Class. Now it’s time to create a view for adding customer. Right Click return view Statement in Create Action Result and Click Add View and Just Create view like following.

CreateView

That’s it now we are ready. Now let’s test it in browser. Like following.

AddNew

Now let’s click and create and then it will redirect us to customer list page like following. Where you can see the newly added details.

View

So that’s it. Its very easy to Insert data with Dapper Micro ORM. Hope you like it…Stat tuned for more.

Note:  For reference of this post you can also see my first post called -Playing with dapper Micro ORM and ASP.NET MVC 3.0.

Shout it

Tags: C#.NET, BRH, #ASP.NET, ASP.NET, ASP.NET MVC, ASP.NET 4.0, Dapper,


Jalpesh
15 · 11% · 3548
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]