Wednesday, July 18, 2012

Differences Between ArrayList and HashTable in C#

If you see the implementation of Hashtable / ArrayList, both are Arrays.
Following are the main differences

Array List
Hash Table
ArrayList is a List
Hash Table is a Map
ArrayList is just a wrapper of the class Array. Its internal representation is same as Array, just we use it to get few extra methods provided with it.
HashTable is same as arraylist, but with a small addition. It is actually an array of a Structure.
In Array List we can ADD only items to the List
In Hash Table we can ADD Data with Key
In Array List we can ADD any DataType value, Every item in ArrayList is treated as Object.
Retrieving by key in Hash Table is faster than retrieving in ArrayList
In one word, ArrayList is Index based.
Hash Table is on both Index based and KeyBased.
ArrayList arraylist = new ArrayList();

Hashtable ht = new Hashtable();

So Ranking :
1. LinkedList (For Large List)
2. List<T>, Dictionary<T>
3. Array, ArrayList, HashTable

Difference between Array and Arraylist in C#

Arrays are strongly typed.

 That is all the elements have to be of the same type. For example an array of integers has to have all integers.  It cannot have a mix of integers and strings.
An arraylist is NOT strongly typed.

You can have a  combination of built in types  (int,string etc) in your arraylist.
Cannot be dynamically resized.

Note : Array.Resize() doesnot actually resize the existing array. It infact creates a new array with the required length and copies values from the old array to new array. Using the Resize is more memory intensive than AddRange() in arraylist
Can be dynamically resized
using the method Arraylist.AddRange()
int[] myIntArray = new int[3];
myIntArray[2] = "Thirty";//Compilation ERROR
ArrayList arraylist = new ArrayList();


Sunday, July 15, 2012

Passing values to UserControl in ASP.Net using C#

In this blog I showed interaction between 2 user controls Here later passing value from user control to main page at Here and now i will show how to send values from main page to user control.

Passing value to user control is very easy when compared to the above two posts mentioned.

Out Put :

show 1 as 001/0001/00001........ using C#

In this post I will show, how to change a string format as the Title says

Out Put :

Saturday, July 14, 2012

Query to display custom Text when columns having null values in SQL, MYsql

Here i am going to show how to display custom Text when there are NULL columns in SQL and MySql as follows...

I had a table name as Childs with the following values. and the query to show values is select Query

select * from Child

Query to Display Custom Value when columns having fixed values in LINQ

As Title states Query to Display Custom Value when columns having fixed values in LINQ can be shown in the images...

I had a table name called partnerinfo with the following values and the query to display is

from p in Partnerinfos
select new

Display custom message when there are no records in GridView using C#

As the Title says Display Custom Message When there are No records to display in GridView can be seen as shown.....

Insert, Edit, Update and Delete with in GridView in ASP.Net using C#

As the title says I am going to explain how to Insert, Edit, Update and Delete within GridView in ASP.Net using C#. It explains the methods of binding Asp.Net GridView control with simple DataSet and also explains the methods like Insert, Edit, Update and Delete function in the GridView control.

This Example is for Beginners in ASP.Net.

The GUI looks like as shown in the image below....

Retrieving Value from UserControl In ModalPopUp in ASP.Net Using C#

In this post I Explained how to interact between two user controls and now I am going to explain, Retrieving Selected value from user control in the modal popup using Delegates, but i am not explaining about delegates.

  • Create a New Website in VS 2008 / 2010, name it as you like. (File -> New -> Web Site)
  • In the Solution Explorer Right Click on the web site you created and press Add New Item
  • Select WebUserControl and name it as you like, in my case UcOwn.ascx
  • In the user control add a panel and within the panel add UpdatePanel
  • With in the UpdatePanel add ModalPopupExtender, hiddenfield, ListBox, label and 3 Buttons  for loading items in the list box, ok button and cancel button.
Naming Controls : 
  1.  hiddenfield = hf1
  2. label = lblselectedValue and Text="Not Yet Selected"
  3. button1 = btnload for loading items to the ListBox1 and Text="Load Items"
  4. button2 = btnOkPopup Text="BtnOk" 
  5. button3 = btnCancelPopup Text="BtnCancel"
  6. remaining controls as default
Now doubleclick on ListBox1 and select AutoPostBack="true" in the properties.

Fixing Instance Failure when connecting to SQL Server 2005/2008 Express

As the title says Instance Failure when connecting to SQL Server 2005/2008 Express as shown in the below image

When connecting to SQL Server by mistake we may get this ERROR. The error connection string is as shown below.