Saturday, June 8, 2013

Entity Framework : There is already an open DataReader associated with this Command

Recently working on an application with entity framework 4.1 When I was retrieving data and updating data with same data context I was getting following error. It was working fine on another machine but on mine it was giving this error.

There is already an open DataReader associated with this Command.

After digging into the problem for some time I have found that I have not opened multiple active result set in my connection string. So what was happening when I retrieved data with entity framework there was an already opened data reader with that and after that I was updating data so we all know that an data reader is always have connected to particular connection. So it was not allowing me to update the data.
So I have added following attribute to my connection string.

“MultipleActiveResultSets=True”

Then I again test above scenario and it was working fine. It’s very easy. Hope you like it. Stay tuned for more..
Share:
Sunday, June 2, 2013

How to call ASP.Net page method with jQuery

In this blog post we are going to learn about how we can call asp.net page methods from jQuery.

What is ASP.Net Page Method?


Page methods are available from ASP.Net 2.0. It’s an alternative to web services in ASP.Net application. This methods are exposed at client side and you can call that page methods directly from JavaScript.It is an easy way to communicate asynchronously with the server using Ajax.

Creating a page method:


So for creating a page method let’s create a asp.net web empty web application.

Calling asp.net page methods with jquery
Share:
Thursday, May 23, 2013

How to sort a data table in C# with LINQ

One of friend today ask how we can sort data table based on particular column? So I thought it’s a good idea to write a blog post about it. In this blog post we learn how we can learn how we can sort database with LINQ queries without writing much more long code. So let’s write a code for that.

using System;
using System.Data;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable dataTable = CreateDataTalble();
            AddRowToDataTable(dataTable);
            Console.WriteLine("Before sorting");
            PrintDatable(dataTable);
            var Rows = (from row in dataTable.AsEnumerable()
                        orderby row["FirstName"] descending
                        select row);
            dataTable = Rows.AsDataView().ToTable();
            Console.WriteLine("==============================");
            Console.WriteLine("After sorting");
            PrintDatable(dataTable);
        }

        public static DataTable CreateDataTalble()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("FirstName", typeof(string));
            dt.Columns.Add("LastName", typeof(string));
            return dt;
        }
        public static void AddRowToDataTable(DataTable dt)
        {
            dt.Rows.Add("Jalpesh", "Vadgama");
            dt.Rows.Add("Vishal", "Vadgama");
            dt.Rows.Add("Teerth", "Vadgama");
            dt.Rows.Add("Pravin", "Vadgama");
        }

        public static void PrintDatable(DataTable dt)
        {
            foreach (DataRow row in dt.Rows)
            {
                Console.WriteLine(string.Format("{0} {1}",
                    row[0], row[1]));
            }
        }
    }
}

Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews