Sep 18, 2012

We have moved

0 comments
Hello Friends,

We have permanently moved to our new portal at Publish Article

Now and onwards we will update our new portal http://www.publisharticle.in

Thank you.

read more

Feb 24, 2012

Enum Examples or How to Bind the DropDownList With Enum?

2 comments
Enum is the type provided by dotnet, it stores constant value in it. When we want to specify some constant value to use in the project then it is very usefull for readability.

In this post I will show you how to declare an enum and how to use it in the program.
Here I have bind the enum to the dropdown list

Declare the enum as below

public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }

In aspx page I have added DropDownList named ddlDays as below

 <asp:DropDownList ID="ddlDays" runat="server">
        </asp:DropDownList>

Now below is the code to bind dropdownlist control with above enum
// Add first item to the drop down list to select lable
        ddlDays.Items.Add("--Select Days--");

        string[] enumNames = Enum.GetNames(typeof(Days));
        foreach (string item in enumNames)
        {
            int value = (int)Enum.Parse(typeof(Days), item);
            ListItem listItem = new ListItem(item, value.ToString());
            //Add one by one item to the drop down list
            ddlDays.Items.Add(listItem);
        }
 













Out put is displayed in the side image.

read more

Feb 14, 2012

Supported languages by SyntaxHighlighter

0 comments
Syntax highlighter is a tool which will highlight the code in correct Syntax. When on your blog or web site you want to show some programming code then it is very useful.


In my next post I will show you how to add Syntax Highlighter in blogger or any webpage.

Below is the list of all the supported languages with their aliases.






Language Aliases
C++ cpp, c, c++
C# c#, c-sharp, csharp
CSS css
Delphi delphi, pascal
Java java
Java Script js, jscript, javascript
PHP php
Python py, python
Ruby rb, ruby, rails, ror
Sql sql
VB vb, vb.net
XML/HTML xml, html, xhtml, xslt

For more detail visit: http://code.google.com/p/syntaxhighlighter/wiki/Languages

read more

Feb 12, 2012

Change cursor to hand on mouseover using jQuery

4 comments
When ever we need to change the mouse cursor using JQuery then we can do it very easily.

In my today's post I will show you how can we change the mouse cursor to the Hand type cursor while user hover mouse on the particular element.
It is very simple just look at the below JQuery code.
   




$(document).ready(function() {
  $("#elementid").hover(function() {
    $(this).css("cursor", "hand");
  });
});

In above code 'elementid' is the name of the element on which you want a mouse pointer as a hand while hovering a mouse over it.

Happy Coding...

read more

Jan 7, 2012

SQL SERVER – 2005/2008 – User Defined Function to Strip HTML String Without Regular Expression

0 comments
Suppose sometimes we are saving HTML string into the database(SQL Server).
Now when we want to display some limited characters on the web page like first 200 char,
return string will not be proper HTML as it will leave some open HTML tag into it and hense it will not render HTML properely on the web page and also disturb our page html.
So to avoide this problem we can strip html from the sql server. I have written an SQL UDF for that as below.

Following UDF takes input as HTML and returns TEXT only.
If there is any single quotes in HTML then it must be replaced with two single quotes while passing to the function as a input.

Create Function [dbo].[StripHTML]
(@HTMLString VarChar(Max))
Returns Varchar(Max)
As
Begin
    Declare @StartChar Int
    Declare @EndChar Int
    Declare @Length Int
    Set @StartChar = CharIndex('<',@HTMLString)
    Set @EndChar = CharIndex('>',@HTMLString,CharIndex('<',@HTMLString))
    Set @Length = (@EndChar - @StartChar) + 1
    While @StartChar > 0 AND @EndChar > 0 AND @Length > 0
    Begin
        Set @HTMLString = Stuff(@HTMLString,@StartChar,@Length,'')
        Set @StartChar = CharIndex('<',@HTMLString)
        Set @EndChar = CharIndex('>',v,CharIndex('<',@HTMLString))
        Set @Length = (@EndChar - @StartChar) + 1
    End
    Return LTrim(RTrim(@HTMLString))
End
Go

Example:
Declare @HTMLString As VarChar(Max) = '<table class="tempwrapper"> '+
 '<tr><td colspan="3">.NET that will convert a string so that it can be eg I would like to convert the string &quot;a &lt; b&quot; '+
 'to &quot;a &#3C; b&quot;.</td> </tr> </table>'
 Select SUBSTRING(@HTMLString,0,100)
 Select SUBSTRING([dbo].[StripHTML](@HTMLString),0,100)
-> <table class="tempwrapper"> <tr><td colspan="3">.NET that will convert a string so that it can be e
-> .NET that will convert a string so that it can be eg I would like to convert the string &quot;a &lt

Here I have attached a screen shot of the UDF at action.










Happy Programming :-)

read more

Dec 17, 2011

Script All the Stored Procedures, Views, Triggers and Functions from The Database

4 comments

In my previous post I have show you how to generate database script using Wizard. In this article I will show you how to generate script for database object programmatically or using query

In SQL Server 2005/2008 Management studio you can script all the database object using ‘SQL Server Script Wizards’. But sometime we do not have the permission to generate a script using wizard then we are help less. But don’t worry now we have a solution for that as well. I will show you how to script all database objects programmatically.

To script All the Stored Procedures from the Database:

DECLARE @ScriptText As VARCHAR(MAX) = ''
DECLARE @AllScriptText As VARCHAR(MAX) = ''

DECLARE script_sp CURSOR FOR
SELECT SM.Definition
FROM SYS.SQL_Modules As SM INNER JOIN SYS.Objects As Obj
ON SM.Object_ID = Obj.Object_ID WHERE Obj.Type = 'P'
OPEN script_sp

FETCH NEXT FROM script_sp INTO @ScriptText

WHILE @@FETCH_STATUS = 0
BEGIN
        --Set @AllScriptText =  @AllScriptText + 'go' +@ScriptText;
        Print @ScriptText;
        FETCH NEXT FROM script_sp INTO @ScriptText
END
--Select @AllScriptText;
CLOSE script_sp
DEALLOCATE script_sp

But Remember if you have created all the procedure with encryption then you will get the null value.

 Now suppose you want all the views as a script then use below query,

DECLARE @ScriptText As VARCHAR(MAX) = ''
DECLARE @AllScriptText As VARCHAR(MAX) = ''

DECLARE script_sp CURSOR FOR
SELECT SM.Definition
FROM SYS.SQL_Modules As SM INNER JOIN SYS.Objects As Obj
ON SM.Object_ID = Obj.Object_ID WHERE Obj.Type = 'V'
OPEN script_sp

FETCH NEXT FROM script_sp INTO @ScriptText

WHILE @@FETCH_STATUS = 0
BEGIN
        --Set @AllScriptText =  @AllScriptText + 'go' +@ScriptText;
        Print @ScriptText;
        FETCH NEXT FROM script_sp INTO @ScriptText
END
--Select @AllScriptText;
CLOSE script_sp
DEALLOCATE script_sp

Now suppose you want all the functions as a script then use below query,

DECLARE @ScriptText As VARCHAR(MAX) = ''
DECLARE @AllScriptText As VARCHAR(MAX) = ''

DECLARE script_sp CURSOR FOR
SELECT SM.Definition
FROM SYS.SQL_Modules As SM INNER JOIN SYS.Objects As Obj
ON SM.Object_ID = Obj.Object_ID WHERE Obj.Type = 'FN'
OPEN script_sp

FETCH NEXT FROM script_sp INTO @ScriptText

WHILE @@FETCH_STATUS = 0
BEGIN
        --Set @AllScriptText =  @AllScriptText + 'go' +@ScriptText;
        Print @ScriptText;
        FETCH NEXT FROM script_sp INTO @ScriptText
END
--Select @AllScriptText;
CLOSE script_sp
DEALLOCATE script_sp

If you need to generate a script for all the triggers from the database then we have to make little bit changes in query. We will join sys.triggers table in place of sys.objects as below.

DECLARE @ScriptText As VARCHAR(MAX) = ''
DECLARE @AllScriptText As VARCHAR(MAX) = ''

DECLARE script_sp CURSOR FOR
SELECT SM.Definition
FROM SYS.SQL_Modules As SM INNER JOIN SYS.triggers As Obj
ON SM.Object_ID = Obj.Object_ID
OPEN script_sp

FETCH NEXT FROM script_sp INTO @ScriptText

WHILE @@FETCH_STATUS = 0
BEGIN
        --Set @AllScriptText =  @AllScriptText + 'go' +@ScriptText;
        Print @ScriptText;
        FETCH NEXT FROM script_sp INTO @ScriptText
END
--Select @AllScriptText;
CLOSE script_sp
DEALLOCATE script_sp

Happy Scripting…….


read more

Author Profile

Total Pageviews

Categories

Followers

 

Sponsors