Monday, 19 April 2010

Get Name of Stored Procedures by Passing Table Name

DECLARE @TABLENAME VARCHAR(50)
SET @TABLENAME='<TableName>' --Pass the Table Name here
SELECT @TableName as [Table Name],A.Name AS [SP Name],B.Text as [SP Text]
from SYSOBJECTS A
INNER JOIN SYSCOMMENTS B
ON A.ID=B.ID
WHERE B.TEXT LIKE '%'+@TableName+'%'
and A.TYPE='P'

Monday, 8 March 2010

Dynamic Columns

DataTable dtbl1 = new DataTable();
dtbl1=c1.FetchRecords("items");

dngrview.DataSource = null;
dngrview.DataBind();
DataTable dt = new DataTable();
for (int i = 0; i <= dtbl1.Rows.Count-1; i++)
{
DataColumn dc = new DataColumn(dtbl1.Rows[i]["ItemName"].ToString() , typeof(System.Int32));
dt.Columns.Add(dc);

}

DataRow dr = dt.NewRow();
dt.Rows.Add(dr);

dngrview.DataSource = dt;
dngrview.DataBind();

Wednesday, 14 October 2009

Lock Folder

1) If you want to lock a folder named pocket in your C:\, whose path is C:\pocket

2) Now open the Notepad and type the following


ren pocket pocket.{21EC2020-3AEA-1069-A2DD-08002B30309D}

3) Where dark is your folder name. Save the text file as loc.bat in the same drive.

4) Open another new notepad text file and type the following


ren pocket.{21EC2020-3AEA-1069-A2DD-08002B30309D} pocket

5) Save the text file as key.bat in the same drive.

6) To lock the pocket folder, simply click the loc.bat and it will transform into control panel icon which is inaccessible.

7) To unlock the folder click the key.bat file. Thus the folder will be unlocked and the contents are accessible.

Wednesday, 18 March 2009

Select Last Day of Month in SQL

SELECT (CASE MONTH(GETDATE())
WHEN 1 THEN 31
WHEN 2 THEN (CASE YEAR(GETDATE())%4 WHEN 0 THEN 29 ELSE 28 END)
WHEN 3 THEN 31
WHEN 4 THEN 30
WHEN 5 THEN 31
WHEN 6 THEN 30
WHEN 7 THEN 31
WHEN 8 THEN 31
WHEN 9 THEN 30
WHEN 10 THEN 31
WHEN 11 THEN 30
WHEN 12 THEN 31
END) AS LastDayOfMonth

Saturday, 27 September 2008

Date Validation in C#

public bool isDate(string strDate)
{
string strRegex = @"^\d{1,2}\/\d{1,2}\/\d{2,4}$";
Regex re = new Regex(strRegex);
if (re.IsMatch(strDate))
return (true);
else
return (false);
}


Name Space to be included::::

using System.Text.RegularExpressions;


How to use this function::::::
if (isDate(txtexpirydate.Text) == false)
{
Err_ind = 1;
lblerror.Text = "Check Expiry Date..!";
}

Monday, 25 August 2008

Try Catch in SQL SERVER 2005

drop proc dbo.P_Product_Name
go
Create proc dbo.P_Product_Name
--P_Product_Name 'Test12'
@Product_Name varchar(100)
as
BEGIN TRY
INSERT INTO T_Table_Test(Product_id, Product_name, today_date)
VALUES(12497, 'Try_Catch',getdate())
END TRY
begin catch
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;

end catch

Generate Identity Column through Query..

Declare @ProductID int
set nocount on
insert into T_Table_Test(Product_Name,Today_Date) values('Testing',getdate())
SET @ProductId = IDENT_Current('T_Table_Test')
print @ProductId