Friday, September 14, 2007

Tree View in Dropdownlist

We all are very much aware of the DropDownList(a server control available in asp .net), the way it functions and the way the data are listed in it.

eg .,
There is another server control available which is < asp:TreeView > which gets rendered something like this


I was wondering whether it is possible to have this tree view inside the dropdown. To start with, I tried binding the dropdown with the treeview and then with xml having various sub levels but I couldn't make up.

So I tried combining the available controls which will produce the look and feel of a drop down box with a tree view. A textbox, button(probably loaded with down arrow image) and a treeview were chosen. To make it behave like a dropdown, the visibility of the div which contains the tree view can be controlled.


protected void downArrowButton_Click(object sender, EventArgs e)
treeViewDiv.Visible = true;

Now, we have a list of items displayed in a tree like structure when the down arrow button is clicked. And when any option is selected the text box should be loaded with it and the tree structure should not be visible in order to make it behave like a drop down box. The code goes something like this,

protected void stateTreeView_SelectedNodeChanged(object sender, EventArgs
if (sender.GetType().ToString().EndsWith("TreeView"))
cityTextBox.Text = stateTreeView.SelectedNode.Text;
treeViewDiv.Visible = false;

This code can further be customised as per one's requirement and can even Ajaxify certain things for better user experience.

The final output which i got was something similar to this,

Makkals, this was my long time plan(to post some technical thing). Kindly bare with me.....

அரசியல்ல இதெல்லாம் சகஜமப்பா!!!!!!

Thursday, September 13, 2007

DateTime format in Sql Server

SQL Server provides a number of options you can use to format a date/time string. One of the first considerations is the actual date/time needed. The most common is the current date/time using getdate(). This provides the current date and time according to the server providing the date and time. If a universal date/time is needed, then getutcdate() should be used. To change the format of the date, you convert the requested date to a string and specify the format number corresponding to the format needed. Below is a list of formats and an example of the output:

How to debug stored procedures in Visual Studio .NET

This step-by-step article explains two ways that you can debug SQL Server stored procedures and the necessary configuration settings and steps for each approach. A Visual Studio .NET developer can use the Server Explorer to debug SQL Server stored procedures independently of any Visual Studio project, or the developer can step into the code of the stored procedure directly from managed code in a Visual Basic, Visual C#, or Visual J# project.Option 1: Debug a stored procedure in standalone mode
Open Server Explorer.NOTE: It is not necessary to add a Data Connection to work with a SQL Server server because SQL Server servers are listed under the Servers node also. You will use the Servers node in the steps that follow; however, you can use a Data Connection to you SQL Server server in the same way.
Under the Servers node in Server Explorer, expand the SQL Server machine name, expand the SQL Servers node, expand the SQL Server instance, expand the Northwind database node, and then expand the stored procedures node.
Right-click the CustOrderHist stored procedure and then click Step Into Stored Procedure.
The Run stored procedure dialog box opens, which lists the parameters of the stored procedure. Type ALFKI as the value for the @CustomerID input parameter and then click OK.
In the Visual Studio design environment, a window opens that displays the text of the stored procedure. The first executable line of the stored procedure is highlighted. Press F11 to step through the stored procedure to completion.
In the Output window, the following message is displayed, which indicates successful execution: The program ‘SQL Debugger: T-SQL’ has exited with code 0 (0×0).
Option 2: Step into a stored procedure from managed code

Create a new Visual Basic Windows Application project.
Drag a Button control from the toolbox to Form1. At the top of the Form1 code window, add the following line of code:
Imports System.Data.SqlClient
Copy the following code into the Button1_Click event procedure:
NOTE: Modify the connection string as necessary for your environment.

Dim cn As SqlConnection
Dim strCn As String
Dim cmd As SqlCommand
Dim prm As SqlParameter
strCn = "Data Source=(local);Initial Catalog=Northwind;" & _
"Integrated Security=SSPI"
cn = New SqlConnection(strCn)
cmd = New SqlCommand("CustOrderHist", cn)
cmd.CommandType = CommandType.StoredProcedure
prm = New SqlParameter("@CustomerID", SqlDbType.Char, 5)
prm.Direction = ParameterDirection.Input
cmd.Parameters("@CustomerID").Value = "ALFKI"
Dim dr As SqlDataReader = cmd.ExecuteReader
While dr.Read
Console.WriteLine("Product ordered: {0}", dr.GetSqlString(0))
End While

In Solution Explorer, right-click the project (not the solution) and open the Property pages. Click Configuration Properties in the tree and then click to select the SQL Server Debugging check box on the Debugging page to enable stored procedure debugging.
Set a breakpoint on the following line of code:Dim dr As SqlDataReader = cmd.ExecuteReader
In Server Explorer, locate and open the CustOrderHist stored procedure as described in Option 1. Right-click the stored procedure and then click Edit Stored Procedure.
Set a breakpoint in the stored procedure on the SELECT statement, which is the only line of executable code.
Press F5 to run the Visual Basic project.
When Form1 appears, click the command button. The code will run to the breakpoint that you set before the stored procedure is called.
Press F11. Code execution steps from the ExecuteReader method into the stored procedure window.
Press F11 again. The single line of code in the stored procedure, the SELECT statement, executes. Then control returns to your Visual Basic project, and the project runs to completion.
To continue to step through the Visual Basic code after you step out of the stored procedure, you must set a second breakpoint in the Visual Basic code after the call to the stored procedure. For example, in the sample code shown in this section, you can set the second breakpoint on the following line:While dr.Read

To step from Visual Studio code into a stored procedure, you must enable SQL Debugging in the Project Properties on the Debugging page.

To step through stored procedure code, you must set a breakpoint in the stored procedure itself. Otherwise, debugging steps over the stored procedure and the window for the stored procedure does not open.

To continue to step through Visual Studio code after debugging steps out of a stored procedure, you must set a breakpoint in the project code at a point after the execution of the stored procedure. Otherwise, the code runs to completion after debugging steps out of the stored procedure.

For setup and configuration issues, refer to the section entitled “Setting Up SQL Debugging” in the Visual Studio .NET documentation.
Limitations of stored procedure debugging
The following is a list of limitations that you may encounter when you debug stored procedures and that you do not encounter when you debug Visual Studio code:

You cannot “break” execution.

You cannot “edit and continue.”

You cannot change the order of statement execution.

Although you can change the value of variables, your changes may not take effect because the variable values are cached.

Output from the SQL PRINT statement is not displayed.

Thursday, July 5, 2007


&nbsp;&nbsp;&nbsp; For people who dont know ,the toString() is one of the methods that are available for all objects in java .

Have you ever used this function??

If yes for what you have used this function??

Hmmm Where did i use this function??

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; In date functions to convert date into string ,when you want to assign an object to a string or if you want to print something which is not a string.Basically when you have a sop(System.out.println())it can print only string values and by default it calls the toString() method for all objects.
Calling a toString() method to convert a date to string is ok and even to convert integer or a boolean to string is ok because in both cases the value of the object is returned as a string without any damage .

What happens when you call it for a user-created-class object.?
When you do this you would get an output like this


&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; And do we get any idea about the object and its values???
No , we just know that it is not null.
I had used this to check if the value is not null . I was wondering why we have this function for all objects until i knew about the "overridding toString()".

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Every class is supposed to override the toString() method
Overriding toString() is when you want to be able to read something meaningful about the objects of your class. Code can call toString() on your object when it wants to read useful details about your object.

if you have a class name

class Biodata
String name;
String age;
// all functions goes here

public String toString()
return "this is biodata class and my name is "+name+ my age is "+age;

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Now if you try to print the object of this class you will get a detailed idea of this&nbsp; object rather than "@&%$%^!###" .
I guess it is one rule that should be followed.Every class should override toString() method.

Powered by ScribeFire.

Tuesday, June 19, 2007

My first article is published

Hi friends,

One of my article about struts and AJAX has been published in the following website .

This is the first article of mine being published.

Saturday, June 9, 2007

Find an element in Array ( .NET )

Most of us will often need to find an element in an array. In C or C++, we can do this by using the FOR loops. In .NET 2.0, we have a build-in method, which is very simple and powerful too. It is similar to ArrayList’s Contains method. The following code snippet will show this.

Private Function MyMethod() as string
Dim countryCodes() As String
countryCodes = “IND,CHI,JPN”.Split(”,”.ToCharArray)
If Array.Exists(countryCodes, AddressOf CountryCodeStartsWith) Then
Return “Exists”
Return “Not Exists”
End If
End Function

Private Function CountryCodeStartsWith(ByVal countryCode As String) As Boolean
dim Country as string = “INDIA”
If Country.startsWith(countryCode) Then
Return True
Return False
End If
End Function

The Array.Exists has two parameters. The first one is nothing but an array where the element is to searched. The second part of the code , which will be confusing for beginners, is a delegate for the function. At the time of execution the elements in CountryCodes - Our Array - will be passed as a parameter to this delegate. also we can customize this matching function very easily.Hope this will help you.

- P

Tuesday, May 22, 2007

Difference between two Dates in C#.NET ?

To find the difference between two dates is very simple in VB — By using DateDiff method. But in C#, there is no direct method to do so. but there is a way to achive this.
For this we need to understand TimeSpan Class.

The following code snippet will show you how to find the difference.

DateTime startTime = DateTime.Now;
DateTime endTime = DateTime.Now.AddSeconds( 75 );
TimeSpan span = endTime.Subtract ( startTime );
Console.WriteLine( “Time Difference (seconds): ” + span.Seconds );
Console.WriteLine( “Time Difference (minutes): ” + span.Minutes );
Console.WriteLine( “Time Difference (hours): ” + span.Hours );
Console.WriteLine( “Time Difference (days): ” + span.Days );

By concatenating all this you will get the difference between two dates. You can also use span.Duration().

There are certain limitations to. The TimeSpan is capable of returning difference interms of Days, Hours, mins and seconds only. It is not having a property to show difference interms of Months and years.

Hope this will help you…

- P

Thursday, April 26, 2007

Core Java Programming

       Core java seems very difficult now a days....

Check out the following statements

        int i=1;

What do you think is the output of the above statements..
It is just a simple assignment and increment statement.

in i++
            i gets incremented only after the execution of the line,
so i=1+1
            so i =2 in second line
but in the third line the value of i should be incremented but as per the execution of the statement,
Value of i is got as 2
What happened to the increment.....

=+ and ++ cant execute in the same statement and same variable


Tuesday, April 24, 2007

Velocity intergration with struts

            Velocity is a Java-based template engine. It permits anyone to use a simple yet powerful template language to reference objects defined in Java code.
            When Velocity is used for web development, Web designers can work in parallel with Java programmers to develop web sites according to the Model-View-Controller (MVC) model, meaning that web page designers can focus solely on creating a site that looks good, and programmers can focus solely on writing top-notch code.
        Velocity separates Java code from the web pages, making the web site more maintainable over its lifespan and providing a viable alternative to Java Server Pages (JSPs) or PHP.

Five steps to Velocity

The recipe for combining Struts and the Velocity Template Engine is simple and straightforward; in fact, you can do it in just five steps:

   1. Place the Velocity JARs in your classpath.
   2. Modify the web.xml file to recognize the Velocity servlet.
   3. Place the Velocity toolbox.xml under your application's WEB-INF directory.
   4. Modify your struts-config to point its views to Velocity templates instead of JSPs.
   5. Create a Velocity template for each page you want to render.

        Let us take up an example to understand better.When we search for an ISBN, it should display the contents of the isbn.. For this example let us execute the five steps..

Step 1. Place the Velocity JARs in WEB-INF/lib

The Step 1 is the easiest.Download velocity jars and place them in WEB-INF/lib

Step 2. Modify web.xml to recognize the Velocity servlet

The next step is to modify the Struts web.xml file to recognize the Velocity servlet and direct all resources

request ending with .vm to the Velocity servlet

  <servlet-name>velocity</servlet-name> //declare the Velocity servlet and give it a handle of velocity.

    <param-name>org.apache.velocity.toolbox</param-name>// toolbox configuration location.


<!-- Map *.vm files to Velocity -->

The Velocity servlet takes a "toolbox" parameter. The toolbox is the place you declare the tools available to

your application.

Step 3. Place toolbox.xml under WEB-INF

The tool box bascially conntains all the tools. We define each of them with the key,scope and the class..

<?xml version="1.0"?>

Step 4. Modify struts-config

    Struts config should be modified to support velocity. There is no much difference if we have a velocity template forward the action to a *.vm pattern

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD
             Struts Configuration 1.0//EN"

        <form-bean name="searchForm" type="app.SearchForm"/>

        <forward name="welcome" path="/"/>

            <forward name="success"
Note that we can use both *.do and *.vm in the same application depending on the requirement.

Step 5. Create a Velocity template

velocity template for the example application's search page.

    $!errors.msgs() //$!errors.msgs() to get any error messages on the error-message queue.
    <FORM method="POST"
      action="$link.setAction('/search')"> //to obtain the URL for the search forward.
      <h2>Book Search</h2>
      ISBN:<INPUT type="text" name="isbn">
      <INPUT type="submit" value="Submit" name="submit">
Velocity template for the results page


  <h1>Book Details</h1>
  <a href="$link.setForward("searchEntry")">Search


    <b>No Pages:</b>$book.pages<br>

The action class sets a book object in session, which is retrieved and displayed in the velocity template.

This is a sample application with velocity and struts. Velocity does seems simpler than JSP's

Friday, April 13, 2007

Garbage Collection...

This is one topic which most of you know about. I was once asked by my senior to read about this.. And yes, i did read about that.

The Java Virtual Machine has 2 primary jobs:
# Execute Code
# Manage Memory

Memory Management involves 3 mail goals

# Allocate Memory from OS
# Manage Java Allocations
# Remove Garbage Objects

Garbage Collection involves around Memory management and it is one major advantage of Java over C or C++. One of our professors were very particular about freeing every memory used in C++ and I am happy that in Java, no need to care about it..
This is the second good reason for shifting to JAVA from C++. Not to forget the first reason "no pointers in java".

Memory allocation in Java is done in the heap, I mean there is one heap and objects are all allocated memory from this heap.

An object is created in the heap and is garbage-collected after there are no more references to it. Objects cannot be reclaimed or freed by explicit language directives.

Objects become garbage when there are no more references to the object.So, how do u say an object has no more references.

If no active threads have reference to this object, It is said eligible for GC.(All programs are said to me executed as threads and it starts executing from the main method.)

The garbage collector checks to see if there are any objects in the heap that are no longer being used by the application. If such objects exist, then the memory used by these objects can be reclaimed. (If no more memory is available for the heap, then the new operator throws an OutOfMemoryException.)

There are several GC algorithms in use today. Each algorithm is fine-tuned for a particular environment in order to provide the best performance. Let us see one of them.

Mark, Sweep and compact Algorithm.

Quite simple
# Mark: identify garbage
# Sweep: Find garbage on heap, de-allocate it
# Compact: collect all empty memory together

Every application has a set of roots. Roots identify storage locations, which refer to objects on the managed heap or to objects that are set to null. For example, all the global and static object pointers in an application are considered part of the application's roots. In addition, any local variable/parameter object pointers on a thread's stack are considered part of the application's roots. Finally, any CPU registers containing pointers to objects in the managed heap are also considered part of the application's roots. The list of active roots is maintained and is made accessible to the garbage collector's algorithm.

When the garbage collector starts running, it makes the assumption that all objects in the heap are garbage. In other words, it assumes that none of the application's roots refer to any objects in the heap. Now, the garbage collector starts walking the roots and building a graph of all objects reachable from the roots. For example, the garbage collector may locate a global variable that points to an object in the heap.

The collector continues to walk through all reachable objects recursively.

Once this part of the graph is complete, the garbage collector checks the next root and walks the objects again. As the garbage collector walks from object to object, if it attempts to add an object to the graph that it previously added, then the garbage collector can stop walking down that path. This serves two purposes. First, it helps performance significantly since it doesn't walk through a set of objects more than once. Second, it prevents infinite loops should you have any circular linked lists of objects.

Once all the roots have been checked, the garbage collector's graph contains the set of all objects that are somehow reachable from the application's roots; any objects that are not in the graph are not accessible by the application, and are therefore considered garbage. The garbage collector now walks through the heap linearly, looking for contiguous blocks of garbage objects (now considered free space). The garbage collector then shifts the non-garbage objects down in memory (using the standard memcpy function that you've known for years), removing all of the gaps in the heap.

There are many other Garbage collection algorithms too..

But what we need to know about them is
1) We never know when they get executed.
When the memory goes low, it is executed. We cannot manually start it. We can ask the compiler to do it but we cannot demand it to do it. It means when we ask it execute GC , it may or may not do it.

To ask the compiler.... use ,

System.gc();// call the static function


Runtime rt = new Runtime();

2) We can manually make the object eligible to be Garbage Collected.. by pointing it to null

int i=5;
After the function of the object or variable is over , one can make it to point to null to make it eligible to be Garbage Collected.

3) It doesn't Guarantee to provide enough space for your application.
When you go out of memory u cant rely on GC to remove all garbage and give u enough memory to run your application. It will remove only what it feels as Garbage , even after removing the garbage you might run out of memory.

Thursday, April 12, 2007

Overloading and Overridding

For long i thought , this is one of the simplest concept in java..
Both types of polymorphism have same method or function names .
In overriding , the function in the super class is over ridden by the subclasses and both have the same name , same parameters and same return types.

Over ridding example

class Animal
public void eat()

class Dog extends Animal
public void eat()//overriding eat of animal
public void befriendly()

public class Test
public static void main(String a[])
Animal a = new Dog(); dogs eat is called because at runtime a is an object if Dog.
a.befriendly();//Complier error.....

Animal a=new Dog (); means that the variable a is a animal reference variable at compile time and Dog's object during run time..
So, even though at runtime a.befriendly(); may run as a is a Dog's object , It will not compile because at compile time "a" is a animal reference.

In Overloading , the function in the same class or super class is overloaded whereby the functions have the same name and should have different number of parameters or different types of parameters and can have different return types.

Overloading Example

class Vehicle
public void parts(String part1)

class van extends Vehicle
public void parts(String head, String part1)// This is not over ridding the parts of the Vehicle class, it is overloading

public void parts(String head, String part1,String part2)

public class test2
public static void main(String a[])
Vehicle van = new van();"asdfasd","fads");//compiler error
Van v= new Van();"DF","Adsfa","Dfd");//legal

In here the Parts() of Vehicle is overloaded by parts of Van and not over ridden.
So when the compiler comes across
Vehicle van = new van();
It is Vehicles reference in the compile time , so"asdfasd","fads");
results in a compiler error..
Though at run time it may seem perfect..

You should keep in mind that

= > The method to be overloaded is decided at compile time.
= > The method to be overridden is decided at run time.
= > You can run only after you have compiled..

Wednesday, April 11, 2007

ERP --- Enterprise Resourse Planning

ERP - Short for enterprise resource planning, a business management system that integrates all facets of the business, including planning, manufacturing, sales, and marketing. As the ERP methodology has become more popular, software applications have emerged to help business managers implement ERP in many different business activities such as inventory control, order tracking, customer service, finance, human resource and so on.

In other words we can consider ERP to be a set of activities supported by mulit-mode application software or other business to manage important parts of business such as product planning, purchasing materials, maintaining inventories, interacting with suppliers and customers, tracking orders etc... . It also includes other aspects of business such as finance management or human resource management.

The term ERP originally implied systems designed to plan the use of enterprise-wide resources. Although the acronym ERP originated in the manufacturing environment, today's use of the term ERP systems has much broader scope. ERP systems typically attempt to cover all basic functions of an organization, regardless of the organization's business or charter. Business, non-profit organizations, non governmental organizations, governments, and other large entities utilize ERP systems.

Some organizations - typically those with sufficient in-house IT skills to integrate multiple software products - choose to only implement portions of an ERP system and develop an external interface to other ERP or stand-alone systems for their other application needs. For instance, the Peoplesoft HRMS and Financials systems may be perceived to be better than SAP's HRMS solution. And likewise, some may perceive SAP's manufacturing and CRM systems as better than PeopleSoft's equivalents. In this case these organizations may justify the purchase of an ERP system, but choose to purchase the PeopleSoft HRMS and Financials modules from Oracle, and their remaining applications from SAP.

Private constructor

What is a Private constructor . Why is a constructor made private.. This private, public and protected access modifiers are used always for two things..
1) To confuse u ;)
2) To allow and deny access to other classes.(As the name)
Private constructors prevent a class from being explicitly instantiated by callers.

I know the next question , When do u want the callers not to instantiate the class.

Whenever a class contains
* only static utility methods
* contains only constants
* type safe enumerations
* singletons
u can make their constructors private...

If the programmer does not provide a constructor for a class, then the system will always provide a default, no-argument constructor. To disable this default constructor, simply add a private constructor to the class. This private constructor can be empty.

Example of a class containing constants

public final class Consts {

* Prevent object construction outside of this class.
private Consts(){

public static final String NEW_LINE = "\n";
public static final String EMPTY_STRING = "";
public static final String SPACE = " ";
public static final String PERIOD = ".";
public static final String TAB = "\t";

//algebraic signs
public static final int POSITIVE = 1;
public static final int NEGATIVE = -1;
public static final String PLUS_SIGN = "+";
public static final String NEGATIVE_SIGN = "-";

the Consts class declared contains only static and final constants . When we have all static values in a class and their values cannot be changed why do you want to instantiate an object for it. We create objects for a class to hold different values of the variable defined in the class. So as the variables are final,w cant modify them and since they are static the same memory space will be used for all the objects instantiated so why should we instantiate for such type classes.