Thursday, June 11, 2009

Get Executable path in .Net CF 2.0

To retrieve the current path or the executable path in .net Compact Framework 2.0, we can use the following code in C#

string curPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);


:)

Thursday, June 4, 2009

DataFormatString to put leading zeros in ASP.NET GridView BoundField Column

If we want to display values like 0001, 0002 rather than 1,2 in the gridview columns, we need to make use of DataFormatString property of asp:BoundField in gridview.

So to put leading zeros or to zero pad the values displayed using bound field in gridview use this...

DataFormatString="{0:0000}"

To show the date in dd/MM/yyyy format, use this...

DataFormatString="{0:dd/MM/yyyy}"

This will be useful when we need to show only the date part and skip the time part.

:)

Tuesday, June 2, 2009

Split a string into records based on delimiter, SQL Server 2005

If you have a string which is separated with some delimiter, say comma. And if you think you need to split the string based on the delimiter and return as a recordset, then this function is for you.

This function will split a string into records based on the delimiter

Usage:

SELECT FROM dbo.SplitStr('Bangalore,Kerala,Mumbai',',')


The result will be

Bangalore
Kerala
Mumbai

This may be helpful if you want to use this in queries like

Select from Table1 Where City in (SELLECT * FROM dbo.SplitStr('Bangalore,Kerala,Mumbai',','))

Which will return you all the records where the City is either Bangalore, Kerala or Mumbai like in our example...

Function : SplitStr