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


Friday, January 30, 2009

List all Stored Procedures,Tables or Views in SQL Server 2000/2005

Some times we need to take a print of all the stored procedures, tables or views from our database in SQL Server 2000/2005. For that purpose first we need to list all the user created stored procedures,tables or views. You can make use of the following queries.

1. To List all user created Stored Procedures
Select name From sys.objects Where type = 'P'

2. To List all User created Tables
Select name From sys.objects Where type = 'U'

3. To List all User Created Views
Select name From sys.objects Where type = 'V'

4. You can retrieve data by giving your own filter values, just list all columns to find what is needed
Select * From sys.objects

Now you can create interesting queries for various analysis or just for information purpose
Example:
Get me all the user stored procedures that are created after 20th jan 2009
Select name From sys.objects Where type = 'P' And create_date > '1/20/2009'

So now you can have your own queries...
:)

Note:
In SQL Server Query Analyser (SQL Server 2000) or SQL Server Management Studio Express (SQL Server 2005), you can save the result of the sql query to a file or can view as text.

Right click in the query window and select "Results To". Now you have three options
1) Results to Text, 2) Results to Grid, 3) Results to File
Select your choice.