22. December 2013 19:24
In a situation I had to create a Data Table manually and add columns and rows to it. Later I wanted to search for a row in this Data Table using LINQ. As soon as LINQ code was fired I got this error: "Specified cast is not valid". Below I am sharing a sample code to simulate this problem and will tell you how to get rid of this error in this particular situation I mentioned above.
public partial class _Default : System.Web.UI.Page
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
DataRow row = dt.NewRow();
row = 1;
row = 2000;
protected void GetRecord(int RowId)
var results = from row in dt.AsEnumerable()
where row.Field<int>("RowId") == RowId
string FetchedRowId = results.ToArray().ToString();
If you execute this code, you will get this error:
The root of this error lies during the creation of columns for the Data Table. Do you notice these lines:
Here if you don't specify the Type of column, the default type considered is 'string'. Mentioning the default type of each column solves this issue:
15. December 2013 14:43
With the release of Visual Studio 2013 comes more improvements to make life of developers even more easier. The release of Visual Studio 2013 came as a surprise though. Few weeks back I downloaded Visual Studio 2012 Express and was excited to start a new MVC application on it. I wanted to submit feedback and some valid reasons to migrate old projects to Visual Studio 2012 to my team in office. My feedback document now requires a revision with the release of 2013. No doubt, the changes looks exciting.
Not only me but most developers wanted to use both MVC and Web Forms together in few situations. One ASP.NET is a move towards this. Visual Studio 2013 provides this option when you create a new Web Forms application.
If you select MVC in [Add folders and core references for:], Visual Studio 2013 creates a new project which includes MVC folders and default Web Forms as shown below: More...
10. December 2013 22:43
I was using Disqus as comment provider but many readers were not able to post a comment and didn't want to go through the registration process. Therefore I disabled Disqus and enabled Simple Captcha Extension of BlogEngine. Because of the static nature of Simple Captcha, I started receiving lot of spam from the last few days. I disabled Simple Captcha and enabled reCAPTCHA extension. But even after several attempts tweaking with reCAPTCHA files, reCAPTCHA image was not appearing with the comment box. I submitted this issue on Twitter and soon got the response from BlogEngine.
The reason for reCAPTCHA image not appearing was the change in the URL. To resolve this follow these steps:
- Go to: wwwroot\App_Code\Extensions\Recaptcha
- Open the file: RecaptchaControl.cs
- Replace the URL: http://api.recaptcha.net/js/recaptcha_ajax.js with http://www.google.com/recaptcha/api/js/recaptcha_ajax.js
This change worked and now reCAPTCHA is working. One more point to note is to disable Simple Captcha before enabling reCAPTCHA Extension.