Pages

Tuesday, September 14, 2010

SQL - Date range query


Sometimes we need to get info from the db with the range provided in the stored procedure based on the date and the the date that we send to stored procedure is of the format "dd-mm-yyyy"
Here is the solution to the problem

exec GetCandidateResume @FromDate=N'07-09-2010',@ToDate=N'30-09-2010'

CREATE PROCEDURE [GetCandidateResume] 
(     
    @FromDate    VARCHAR(20),
    @ToDate        VARCHAR(20)
)     
AS 
SELECT
    CandidateId,
    CandidateName
FROM tbl_CandidateInfo
WHERE
    (CONVERT(DATETIME,CONVERT(VARCHAR(12),CandidateAppliedDate,105),105) >=CONVERT(DATETIME, @FromDate, 105))
    AND
    (CONVERT(DATETIME,CONVERT(VARCHAR(12),CandidateAppliedDate,105),105) <=CONVERT(DATETIME, @ToDate, 105))


Hoping that this will help.
:)

Thursday, September 9, 2010

How to add Microsoft Chart control in ASP.Net

This article will show you how to add Microsoft Chart on your web page.

First Download and install this.

When the RenderType property is set to ImageTag, the Chart control saves the rendered chart images as files in memory or on disk (For more information, see Chart Image Rendering). You can specify how the Chart control manages the image files. To do this, use the ImageStorageMode property.
In the ImageStorageMode property, you choose to use the chart HTTP handler to manage image files or to manage them manually.

By default, the ImageStorageMode property is set to UseHttpHandler. This causes the Chart control to use the ChartHttpHandler that is registered in the Web.config file to manage the rendered chart images.

Now create a page and drag and drop the chart control.
Eg:
<asp:Chart ID="Chart1" runat="server" Height="280px" IsMapEnabled="False" IsSoftShadows="False"
        Palette="Excel" Width="380px" ImageLocation="../writereaddata/Chart_#SEQ(25,5)" ImageStorageMode="UseImageLocation">
</asp:Chart>

Now you need to do some settings in the Web.Config file

When you drag a Chart control from the Toolbox onto the design surface of the ASP.NET page, the ChartHttpHandler is automatically registered in the Web.config file as "ChartImageHandler". You can configure ChartImageHandler's behavior in the <appSettings> element. The applicable code section is provided below with the automatically generated settings:

<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;" />
</appSettings>

To manage rendered chart images manually, set the ImageStorageMode property to UseImageLocation, and then set the ImageLocation property to an absolute or relative path.

You can insert three different keywords into the ImageLocation property.


Keyword Description
#UIDGenerate a unique identifier for each rendered chart image. For example: "~/Temp/ChartPicture#UID".
Using this keyword ensures that the server replies each page request with the correct rendered image. You must manually remove old files. Otherwise the number of files will grow indefinitely.


#SEQ(maxFiles,minutes)Generates a file sequence number, up to the number defined by maxFiles, then start the sequence again and replace the first file in the sequence. For example: "Picture_#SEQ(300,5)" generates the following file names (assuming ImageTypePng): Picture_000001.jpg, Picture_000002.jpg, ... set to
The minutes parameter specifies the timeout for each file in the sequence. However, it does not guarantee the validity of a filename for the specified period. If a file is recycled before its timeout period is exceeded, the file a warning message is inserted into the Application Event Log. You should set the maxFile parameter to a reasonably large number to avoid image files being overridden inappropriately.
#NOGUIDPARAM

Removes the GUID string from the image file's URL. For example: "Picture_#SEQ(300,5)#NOGUIDPARAM".
By default, the Chart control adds a GUID string to the image URL.