PetaPoco: Binding a GridView with PetaPoco query result.

PetaPoco is a simple but fast tiny ORM. It is not a full-fledged ORM like NHibernate but a no-fuss easy implementation of ORM. It is a single C# file which you can attach in your project. You can even use NuGet to directly download and integrate it in your project.

PetaPoco has some interesting features like:

  • Support for T4 templates to generate schema from POCO classes.
  • Retrieve paged results automatically.
  • SQL support. No need for strict Linq syntax.
  • Fast.
  • and above all, no external dependencies. Comes as a single C# file.
  • Rather than using automatic mapping, you can use ExplicitColumns attribute to show only the columns to be mapped.

In this post I show you how to query a table using PetaPoco and how to bind a GridView with the result. As discussed above, here I prefer to use ExplicitMapping of table and individual column.

Here goes our basic class: Continue reading

Changing default date format of your ASP.NET application

I messed with this issue for about a month. I recently migrated an old ASP.NET 2.0 application on a private server with Windows 2008 Server R2 Enterprise OS installed. The application consists of few entry forms where date is to be entered in dd/mm/yyyy format. This application has a TextBox to enter the date and not a DateTime picker. Sometimes DateTime picker is not easy to work with when you need to enter old dates often and if you want to keep it null sometimes.

ASP.NET shows error: “Input String was not in a correct format” when date is entered in dd/mm/yyyy format. I re-checked SQL Server documentation, changed SQL Server’s default language for default login (though not recommended), but nothing seemed to solve the problem.

My last workaround with IIS Settings solved the issue.

I am using Windows Server 2008 R2 which comes with IIS 7. Open IIS and right-click the virtual directory of your application. Now select Properties and in the right pane you could see an option: .NET Globalization. Continue reading

Handling nasty Crystal Reports issues

With this article, I am starting a small series of tips and tricks to handle few irritating issues of Crystal Reports. This post covers a couple of issues:

Issue 1:  Crystal Report Viewer’s Print and Export button not working.

Solution: This is a bug which is addressed by Crystal Reports Service Packs. If you are using Crystal Reports from within Visual Studio, you need to download Crystal Reports for Visual Studio service pack. There are a couple of Hot Fixes and Security Updates released to patch further issues:

  1. Visual Studio 2005 Service Pack 1 Crystal Reports Security Update
  2. Crystal Reports Hot Fix for Visual Studio 2005

Issue 2:  Font size gets automatically reduced when printing or exporting the report to PDF.

Solution: The update to this issue (Track ID ADAPT00145285) comes with a PDF document which states that this scaling was intentionally done. This issue really troubles because you are not aware of the actual font size till you take the print. Before fixing this issue, I had to double the font-size in my report to get a normal font size in the printed report. Continue reading

How to get rid of error: “Unable to find the report in the manifest resources.”

This issue looks like a Crystal Report error but, in reality it has nothing to do with Crystal Reports.

After tweaking for about a week, I finally resolved this error. This error is usually flashed when either:

1.     You changed the version of Visual Studio.

Have you recently migrated an old project from Visual Studio 2005 to 2008? If this is the case, open the .rpt in Visual Studio designer and re-save the .rpt file. This makes changes to the underlying designer file.

2.     You modified the NameSpace of your project and somehow, internally, Crystal Reports is assuming old NameSpace.

If you imported an old project (containing .rpt files) into a new project, then the designer file of your .rpt file must comply with the current project NameSpace. Open the code behind of your report file and check the NameSpace being used in the Full Resource Name property.

3.     Your reports are located inside a folder in your Visual Studio solution and it is likely that the folder name is the cause of the problem.

Often developers create folders Continue reading

How to make JQuery work with ASP.NET Web Content Form?

In an ASP.NET application, making JQuery work with a Master Page and Web Content Form is often a matter of confusion for beginners. Since the Web Content Form doesn’t have a HTML HEAD section, novice programmers often get baffled on where to put references to JQuery necessary files and CSS files.

Below I show you how simply you can make JQuery work in an application with a Master Page and a Web Content Form. To make this example work, you need to download few files and add their references to your Visual Studio project. This example uses Visual Studio 2008 with .NET Framework 3.5 SP1.

JQuery core file needed


You can download this file from JQueryUI website.

JQuery DatePicker plugin

I am taking a JQuery DatePicker plugin from Keith Wood’s blog.

A DatePicker can easily be added as a popup to a text field or inline in a division or span with appropriate default settings. The popup shows when the field gains focus and is closed by clicking on the Close link or clicking anywhere else on the page. You can also remove the DatePicker widget if it is no longer required.

We need two files of this plugin to display a simple DatePicker: Continue reading

3 Alternative Frameworks for .NET Web Development

It is a time of choices. For any type of application, you have a variety of languages, frameworks and tools. Developers are more passionate than before and this passion groups them and a new framework is born.

Below is the list of few alternative frameworks for web development on the .NET platform. One of them has grown mature enough to cross the ASP.NET boundaries in terms of abstraction where others are in a process of maturity but rich enough to simplify your web development now.


OpenRasta is a resource-oriented framework for .NET enabling easy ReST-ful development of web sites and services. It is written in C# and is designed to run on .NET 2.0 and above, and can co-exist peacefully with your existing ASP.NET and WCF deployments. It is completely FREE and ships with an MIT license. You are explicitly allowed to do whatever you want with the code, including shipping it as part of closed-source software. No cost involved, no hidden agenda, free for all.

Because OpenRasta is built on best practices, it is by far one of the most extensible frameworks, with more than a dozen extensibility points. It gives you freedom to change the behavior if you don’t like anything in the existing way.

OpenRasta relies on three concepts: Resources, Handlers and Codecs. Separation of concerns is enforced throughout the framework by separating the handling of resources and their rendering. This means less breakage in your code, looser coupling and code which is easy to navigate and read. Loose coupling and dependency injection are at the core of the framework, Continue reading