Archive for the ‘Uncategorized’ Category

AUTOMATICALLY CREATE PROCEDURE FOR INSERT RECORDS | GENERATE SCRIPT AROMATICALLY
CREATE FUNCTION [dbo].[FN_CreateStoredProcedureforInsertRecord]
(
    @TableName NVARCHAR(100),–table name
    @ProcedureName NVARCHAR(100)–procudure name you want to give it.
)
RETURNS NVARCHAR(MAX)
AS
BEGIN

    DECLARE @PRMNAME NVARCHAR(1000)
    DECLARE @PrmA1 NVARCHAR(1000)  –It will contain parameters ex @PramA1 = ‘@Id,@EmployeeName,….’
    SET @PrmA1 = ”
    DECLARE @PROC_Name NVARCHAR(100)
    SET @PROC_Name = @ProcedureName  –Procedure name
    DECLARE @RESULT NVARCHAR(MAX)
    SET  @RESULT = ” — Final procedure script
    DECLARE @CurrentCLMNAME NVARCHAR(100) — It will be used in loop for storing the current column name
    DECLARE @CLMNAMES NVARCHAR(MAX) — It will contain the column name ex @CLMNAMES = ‘Id, EmployeeName’
    SET @CLMNAMES = ”
    DECLARE @VALUES NVARCHAR(MAX)  –It will contain values ex @VALUES = ‘@Id,@EmployeeName,….’
    SET @VALUES = ”
    DECLARE @i INT
    SET @i = 0
    DECLARE @j INT
    SET @j = 0
    DECLARE @IdentityColumn NVARCHAR(50)
    SET @IdentityColumn = ”
    
    –LOOP FOR GET TABLE FILD NAMES AND CREATE FORMAT AS  @FildName1,@FildName2…
    DECLARE CUR_LOOP CURSOR
        FOR SELECT ‘@’+ CASE WHEN (data_type = ‘nvarchar’ OR data_type = ‘varchar’) then  (column_name + ‘ ‘+ data_type +
        ‘(‘+
        (CASE WHEN (CONVERT(NVARCHAR(5),CHARacter_maximum_length) = -1 )
        THEN ‘MAX’
        ELSE CONVERT(NVARCHAR(5),CHARacter_maximum_length)
        END
        )+’)’) else (column_name + ‘ ‘+ data_type) END AS [ClmType]
        FROM information_schema.columns
        WHERE table_name = @TableName
    OPEN CUR_LOOP
    FETCH NEXT FROM CUR_LOOP INTO @PRMNAME
    WHILE @@FETCH_STATUS=0
            BEGIN
            IF(@j<>0)
                BEGIN
                    SET @PrmA1 = @PrmA1 + @PRMNAME+’,’+CHAR(13)+’  ‘
                END
                SET @j = @j + 1
                FETCH NEXT FROM CUR_LOOP INTO @PRMNAME
            END
    CLOSE CUR_LOOP
    DEALLOCATE CUR_LOOP
    –END  

–LOOP FOR GET TABLE FILD NAMES AND CREATE FORMAT AS  SET FildName1 = @FildName1,FildName2 = @FildName2…
    DECLARE CUR_LOOP CURSOR
    FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =@TableName
    OPEN CUR_LOOP
    FETCH NEXT FROM CUR_LOOP INTO @CurrentCLMNAME
    WHILE @@FETCH_STATUS=0
            BEGIN
                IF(@i<>0)
                BEGIN
                    SET @VALUES = @VALUES +’@’+@CurrentCLMNAME+’,’+CHAR(13)
                    SET @CLMNAMES = @CLMNAMES + @CurrentCLMNAME+’,’+CHAR(13)
                    SET @RESULT =  @RESULT + @CurrentCLMNAME + ‘ = @’+ @CurrentCLMNAME + ‘,’+CHAR(13)+’  ‘
                END
                ELSE
                BEGIN
                SET @IdentityColumn = @CurrentCLMNAME
                END
                SET @i = @i + 1
                FETCH NEXT FROM CUR_LOOP INTO @CurrentCLMNAME
            END
    CLOSE CUR_LOOP
    DEALLOCATE CUR_LOOP
    –END
    
    –CREATE THE FORMAT OF PROCEDURE WITH THE HELP OF @PrmA1 AND Result… variables…
    — +CHAR(13)+ is for new line
    SET @RESULT = ‘CREATE PROC ‘+@PROC_Name
    +CHAR(13)+'(‘
    +CHAR(13)+’   ‘+ SUBSTRING(@PrmA1,0,(LEN(@PrmA1)-1))
    +CHAR(13)+’)’
    +CHAR(13)+’AS’
    +CHAR(13)+’BEGIN’
    +CHAR(13)+’ INSERT INTO ‘+@TableName
    +CHAR(13)+'(‘
    +CHAR(13)+ SUBSTRING(@CLMNAMES,0,(LEN(@CLMNAMES)-1))
    +CHAR(13)+’)’
    +CHAR(13)+’VALUES(‘
    +CHAR(13)+ SUBSTRING(@VALUES,0,(LEN(@VALUES)-1))
    +CHAR(13)+’)’
    +CHAR(13)+’END’
    RETURN  @RESULT    
END

After Sucessfully  executed above script.

Now run above function:

select [dbo].[FN_CreateStoredProcedureforInsertRecord](‘Topic’,’inserttopic’)

See screenshot:

Image

Now copy output and execute.

 

 

There is no editor available for .vb file
There is no editor available for .cs file

You might face above issue while trying to open an aspx file in design view in visual studio 2008

You might face above issue while trying to open a vb file in visual studio 2008

You might face above issue while trying to open a cs file in visual studio 2008

Wait you don’t need to reinstall the whole package.

Follow below steps

open cmd

navigate to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

run devenv.exe /setup

wait until it ends

run visual studio, it should be working now.

if not, follow all above steps and at last

run devenv /resetskippkgs

run visual studio, it should be working now.

if it still does not work, install visual studio sp1 from following link

http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13276

follow the steps mentioned above. It will work now.

Please let me incase.

Mayank Arora

Android vs Windows Phone 7

Posted: July 8, 2011 in Uncategorized

Android-vs-Windows-Phone-7-Comparison-Chart

Locations of visitors to this page

      System.Data.OleDb.OleDbConnection connection;
       System.Data.OleDb.OleDbCommand command= new System.Data.OleDb.OleDbCommand();
       string sql = null;
       connection= new System.Data.OleDb.OleDbConnection(“provider=Microsoft.Jet.OLEDB.4.0;Data Source=’c:\\book11.xls’;Extended Properties=Excel 8.0;”);
       connection.Open();
       command.Connection = connection;
       sql = “Update [Sheet1$] set name = ‘Xyz’ where id=1”;
       command.CommandText = sql;
       command.ExecuteNonQuery();
       connection.Close();

SELECT S.Name FROM Sysobjects S

INNER JOIN Sys.objects SS

ON S.id  =  SS.[object_id]  WHERE  S.xtype = ‘U’

AND CONVERT(NVARCHAR(10), SS.modify_date, 105)  = CONVERT(NVARCHAR(10), GETDATE(), 105)

SELECT Name, xtype INTO DeleteDBItemTable FROM sysobjects WHERE Xtype IN (‘P’, ‘FN’, ‘TF’)
SELECT * FROM DeleteDBItemTable
WHILE EXISTS(SELECT TOP 1 1 FROM DeleteDBItemTable)
BEGIN
DECLARE @name NVARCHAR(2000)
DECLARE @xtype NVARCHAR(2000)
DECLARE @command NVARCHAR(2000)
SELECT TOP 1 @name = Name , @xtype = xtype FROM DeleteDBItemTable
IF(@xtype = ‘P’) SELECT @command = ‘DROP PROCEDURE ‘ + @name
ELSE SELECT @command = ‘DROP FUNCTION ‘ + @name
EXEC sp_executes @command
DELETE FROM DeleteDBItemTable WHERE Name = @name AND xtype = @xtype
END
DROP TABLE DeleteDBItemTable

Sometimes during web page validation we all want to remove all special characters entered by the user. This really easy, you can use client side RegEx library to do same.

This is specially useful when you want avoid all the characters like < >. These can cause scripting attack on your site.

Here are the examples

<input type=”text” value=”this is <script/> tag.” onblur=”validateScriptTags(this)”/>

Here is the validateScriptTags function

function validateScriptTags(sender){
var newValue = sender.value.replace(/[<>]+/g, ”);
sender.value = newValue;
}

above replaces all < > to empty string. You can replace it to any value just by changing the value in replace function.

similarly if you just want to allow A-Z, a-z, 0-9 only in textbox inputs you can do something like below

var newValue = sender.value.replace(/[^a-zA-Z0-9]+/g, ”);
sender.value = newValue;