Skip to main content

Posts

Showing posts from 2010

Checking for Ajax Request

function AjaxRequest() { var request = null; if(typeof window.XMLHttpRequest != "undefined") {/*most modern browsers*/ request = new XMLHttpRequest(); } else if(typeof window.ActiveXObject != "undefined") {/*IE 6 browswer*/ try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch(err) { request = null; } } return request; }

Which Dictionary object should you use?

Hashtable SortedList String Dictionary List Dictionary Hybrid Dictionary NameValue Collection Retrieved by name Yes Yes Yes Yes Yes Yes Retrieved by Index Yes Yes Yes Yes Yes Yes Sorted by default No Yes No Key type Object String String (Strongly typed) Object Object String/ Integer Value type Object Object String Object Object Object Performance Optimised for fewer than 10 items Uses List Dictionary for small no of item. Changes to Hashtable as list grows Allows multiple value for a key

How to make a Custom Sort Function

You can create your won custome IComparer implementation to control sort order. While IComparable.CompareTo method controls the default sort order for a class, IComparer.Compare can be used to provide custom sort order. For e.g. following class which implements IComapere, provides custom reverse sort public class reverseSort : IComparer { int IComparer.Compare(Object y, Object x) { return ((new CaseInsensitiveComparer()).Compare(x, y)); } } //test class ArrayList al = new ArrayList(); al.AddRange(new String[] {"This", "is", "a", "Amazing", "world", "of", "Collections" }); //default sort order ascending al.Sort(); foreach (object o in al) { Console.WriteLine(o.ToString()); } //custom sort order al.Sort(new reverseSort()); foreach (object o in al) { Console.WriteLine(o.ToString()); }

Error: Could not find installable ISAM

If you are getting error: "Could not find installable ISAM" while you are trying to connect to Excel file using Microsoft Jet OLEDb provider, here are are some possible solutions 1. Check the connection string. This is the most common cause. To connect to Excel file, you have to specify Extended properties in a connection string. The following connection string in a C# rogrram. string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\""; Pay attention to the double inverted commas " for Extended Properties value. If these are missing, you will get above error. Please note becuase " are part of the string you need to use escape character \ for C# for " for VB. 2. If above doesn't solve the problem, try Help -> Detect & Repair in Excel. 3. If you still have problem, try Microsoft solution http://support.microsoft.com/kb/209805 If this doesn't solve t