Pages

Tuesday, April 30, 2013

What is Differences between Stored Procedures and Functions

Introduction
This article will be explain what Differences between Stored Procedures and Functions. There are following Differences between Stored Procedures and Functions.
  1. Procedure can return zero or n values whereas function can return one value which is mandatory.
  2. Procedures can have input/output parameters for it whereas functions can have only input parameters.
  3. Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
  4. Functions can be called from procedure whereas procedures cannot be called from function.
  5. Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
  6. We can go for transaction management in procedure whereas we can't go in function.
  7. Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
  8. UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
  9. UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
  10. Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
Stored Procedure
A Stored Procedure is a program (or procedure) which is physically stored within a database. They are usually written in a proprietary database language like PL/SQL for Oracle database or PL/PgSQL for PostgreSQL. The advantage of a stored procedure is that when it is run, in response to a user request, it is run directly by the database engine, which usually runs on a separate database server. As such, it has direct access to the data it needs to manipulate and only needs to send its results back to the user, doing away with the overhead of communicating large amounts of data back and forth.
create proc myProc(@a int , @b int)
as
declare @s int
set @s=@a + @b
return @s
to execute procedure
declare @m int
exec @m= myProc 10,20
print @m
User Defined Function
A user-defined function is a routine that encapsulates useful logic for use in other queries. While views are limited to a single SELECT statement, user-defined functions can have multiple SELECT statements and provide more powerful logic than is possible with views.
create function myFunction(@a int, @b int)
return int
as
begin
declare @s int
set @s=@a + @b
return @s
end
To execute function
select dbo.myFunction(10,20)
User defined functions have three main categories:
1. Scalar-valued function - returns a scalar value such as an integer or a timestamp. Can be used as column name in queries.
2. Inline function - can contain a single SELECT statement.
3. Table-valued function - can contain any number of statements that populate the table variable to be returned. They become handy when you need to return a set of rows, but you can't enclose the logic for getting this rowset in a single SELECT statement.

select distinct * into temptable from emp1
delete from emp1

insert into emp1  select * from temptable

Monday, April 22, 2013

Enable USB Port in Windows 8

Introduction
In my previous article we discused how to disable a USB port in Windows 8. This article explains how to enable a USB port in Windows 8. We need to block a USB port when we want to protect our computer from viruses and other vulnerabilites from USB ports. To disable the USB port in the previous article we used a Registry Editor setting so to enable a USB port we can also use the Registry Editor setting. And this example only works for when the USB is blocked by a Registry Editor setting.
How to enable a USB port in Windows 8.
Step 1
Go in the search box and type "Run" and click on the application that is shown or press "Win + R".
Search-In-Windows8.jpg
Step 2
In the run window type "regedit" and click on "OK".
Run-In-Windows8.jpg
Step 3
"Registry Editor" window will be opened.
Registry-Editor-Windows8.jpg
Step 4
In the Registry Editor go to "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR".
USBTOR-Windows8.jpg
Step 5
In the right panel double-click on "Start" and a new window will be opened.
Start-Option-Windows8.jpg
Step 6
In this window type "3" in the value's data and click on "Hexadecimal", click on "OK".
Enable-USB-Setting-Windows8.jpg
Step 7
Restart your computer to apply this setting.
To Disable a USB port visit this link:

Fix Windows Store Apps Error: This App Wasn't Installed

Introduction
The Windows 8 Store is a new feature in Windows 8 by which you can download and install applications and games. Sometimes however when you try to install an application from the Windows 8 Store the installation fails and you get the error message "this app wasn't installed-view details". In some cases it installs about 50% and then just gets stuck there, or you might get some error code or it may just say that it is unable to install it.
In this article we explain how to fix the Windows 8 Store download problem. This type of problem occurs because your Windows firewall may be disabled or a proxy is not set properly.
Error-In-Windows8.jpg
How to fix the Windows 8 Store download problem
Step 1
Open Internet Explorer and click on setting and select "Internet options".
Internet-Explorer-Windows8.jpg
Step 2
A new window will be opened. In this window go to the "Connection" tab and click on "LAN Settings".
Internet-Option-Windows8.jpg
Step 3
In this step click on "Advanced".
Lansetting-Windows8.jpg
Step 4
In this step delete the proxy address and click on "OK" and exit from Internet Explorer.
Proxy-Setting-Windows8.jpg
Step 5
Go to the search box and type "Cmd" and open a command prompt as administrator.
Step 6
In the command prompt enter the command "netsh winhttp set proxy :port". For example: "netsh winhttp set proxy 192.168.1.1:8888" then Enter.
Command-Prompt-Windows8.jpg
Step 7
After setting the proxy you will see your current proxy. Exit from the command prompt.
Set-Proxy-Windows8.jpg
Step 8
Now go to the Windows Store and try to install applications.

Saturday, April 20, 2013

Play MKV Video in Windows 8 Media Player

Introduction
In this article we are going to explain how to play a Windows Media Player (.mkv or .avi extension or H264) file in Windows 8. You perhaps know that the built-in Windows Media Player is not able to open or play the latest video format like .mkv, .avi, flv etc. in each version of Windows. When you try to play this type of file then it shows an error "Windows Media Player can't play this file". This problem also exists with Windows 8.
To solve this problem you have to add an external codecs pack to the Windows Media Player. Because Microsoft provides limited codecs packs with Windows Media Player. After adding a codecs pack you can easily play a .mkv file with Windows Media Player and you can also play .avi, .flv, .ogv, .xvid etc. format files with Windows Media Player.
You can download Windows 8 codecs packs from this link:
How to add external codecs packs to Windows 8 Media Player.
Step 1
First try to play a ".mkv" file with the Windows Media Player. It will show an error.
Not-Suported-Media-Windows8.jpg
Step 2
Download a codecs pack and right-click and select "Run as administrator".
Run-As-Admin-Windows8.jpg
Step 3
Follow the installation steps and finish the installation.
Codec-Windows8.jpg
Step 4
After installing a codecs pack, restart the computer and try to open a .mkv file with Windows Media Player.
Play-Mkv-File-Windows8.jpg

How to Activate Windows 8


Introduction
In this article we are going to explain how to activate Windows 8. To activate Windows 8 you must have a valid product key and network connection.
There are several ways to activate Windows 8 but in this article we are using a command prompt to activate Windows 8 and you can also use this article to change the Windows 8 product key.
How to activate Windows 8
Step 1
Go to the search box and type "Cmd" and right-click on the command prompt icon and select "Run as Administrator".
Run-As-Admin-Windows8.jpg
Step 2
In the command prompt type "slmgr.vbs -ipk <insert your product key here>" and press the "Enter" button. A message will be displayed with the product key in it. In this example we are using the product key for example. You can use another product key for activation.
slmgr.vbs -ipk {insert your product key here}
Insert-Product-Key-Windows8.jpg
Step 3
After inserting the product key type "slmgr.vbs -ato" and press Enter. A message will be displayed informing you that the product was activated successfully.
slmgr.vbs -ato
Insert-Command-Windows8.jpg
Step 4
Now go to the Desktop screen and right-click on the "My Computer" icon and select "Properties". Now you will see "Windows is Activated".
 Windows-Activated-Windows8.jpg

Set Proxy For Metro Apps in Windows 8


Introduction
In this article we are going to explain how to configure a proxy server for a Metro Application in Windows 8. By default we can set a proxy server for Internet Explorer that works for all applications but sometimes it does not work correctly for Metro Applications in Windows 8 for some reason. When you try to open a Metro Application then it shows the message "Your PC is not connected to the Internet. To use this application connect to the Internet and then try again".
This type of problem occurs because the proxy server is not configured for Metro Applications. To configure the proxy there are two ways we can configure the proxy server. The first is to import proxy settings from Internet Explorer to WinHTTP using the Netsh command and another is to configure the proxy server using the Group Policy Editor.
Method 1
Configure the proxy server using the Netsh command to import proxy settings from Internet Explorer to WinHTTP
Step 1
Open a command prompt as an Administrator.
Command-Prompt-Window-Windows8.jpg
Step 2
Type in the following command and press the Enter button.
Netsh winhttp import proxy source=ie
Run-Command-In-Command-Prompt-Windows8.jpg
Step 3
Restart your computer to apply this setting.
Method 2
Configure the proxy setting using the Group Policy Editor.
Step 1
Go in the Search box and type "GPEDIT.MSC" and click on Application that is shown.
Search-Box-Windows8.jpg
Step 2
The Group Policy Editor window will be opened.
Group-Policy-Editor-Windows8.jpg
Step 3
In the Group Policy Editor Window go on "Computer Configuration > Administrative Template > Network > Network Isolation".
Network-Isolation-Windows8.jpg
Step 4
In this step double-click on "Internet proxy servers for Apps" or click on "Edit Setting".
Internet-Proxy-Server-Windows8.jpg
Step 5
The "Internet proxy servers for Apps" window will be opened. In this window click on "Enable" and enter the proxy name in "Domain Proxies". Click "OK" and restart your computer.
 Set-Proxy-Window-Windows8.jpg

Find Google Page Rank in ASP.NET


Introduction
In this article we are going to explain how to find Google Page Rank of specifics webpage in Asp.net. Page Rank is an internal metric Google maintains that indicates how popular Google thinks a web page is. The value is calculated by how many websites link to that page, and how popular those websites are. The minimum value of page rank is 0 and maximum value is 10.
While Page Rank is an internal metric that is being recalculated all the time, Google also maintains a public Page Rank, which is updated from the internal Page Rank several times a year. There are several website available that can you use for find web page rank, you can also use Google toolbar for find page rank buts here we are going to find page rank of web page Programmatically.
Step 1
Open visual studio and start to create new website.
Step 2
In "Dafault.aspx" page add following controls.
<form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Enter your url"
            style="top: 371px; left: 508px; position: absolute; height: 19px; width: 82px">
        </asp:Label><asp:TextBox ID="UrlText" runat="server"
            style="top: 366px; left: 609px; position: absolute; height: 23px; width: 208px">
        </asp:TextBox>
    </div>
    <p>
        &nbsp;</p>
    <p>
        <asp:Button ID="FindPageRankBtn" runat="server" Text="FindRank"
            onclick="FindPageRankBtn_Click"
            style="top: 362px; left: 842px; position: absolute; height: 26px; width: 83px" />
    </p>
    <asp:Label ID="ShowRank" runat="server"
       
        style="top: 431px; left: 612px; position: absolute; height: 19px; width: 300px"
        ForeColor="#FF3300" Font-Bold="True"></asp:Label>
    </form>
Step 3
In "Default.aspx.cs" add following namespace.
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
Step 4
Here is "Default.aspx.cs" complete page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

public partial class GooglePageRenk : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void FindPageRankBtn_Click(object sender, EventArgs e)
    {
        GooglePR Gpr = new GooglePR();
        string Myurl = UrlText.Text;
        int googlePageRank = Gpr.MyPageRank(Myurl);
        ShowRank.Text =" Google page rank is: :-" + googlePageRank.ToString();
    }

    public class GooglePR
    {
        public GooglePR()
        {

        }
        private const UInt32 myConst = 0xE6359A60;
        private static void Hashing(ref UInt32 a, ref UInt32 b, ref UInt32 c)
        {
            a -= b; a -= c; a ^= c >> 13;
            b -= c; b -= a; b ^= a << 8;
            c -= a; c -= b; c ^= b >> 13;
            a -= b; a -= c; a ^= c >> 12;
            b -= c; b -= a; b ^= a << 16;
            c -= a; c -= b; c ^= b >> 5;
            a -= b; a -= c; a ^= c >> 3;
            b -= c; b -= a; b ^= a << 10;
            c -= a; c -= b; c ^= b >> 15;
        }
        public static string PerfectHash(string theURL)
        {
            string url = string.Format("info:{0}", theURL);
            int length = url.Length;
            UInt32 a, b;
            UInt32 c = myConst;
            int k = 0;
            int len = length;
            a = b = 0x9E3779B9;
            while (len >= 12)
            {
                a += (UInt32)(url[k + 0] + (url[k + 1] << 8) +
                     (url[k + 2] << 16) + (url[k + 3] << 24));
                b += (UInt32)(url[k + 4] + (url[k + 5] << 8) +
                     (url[k + 6] << 16) + (url[k + 7] << 24));
                c += (UInt32)(url[k + 8] + (url[k + 9] << 8) +
                     (url[k + 10] << 16) + (url[k + 11] << 24));
                Hashing(ref a, ref b, ref c);
                k += 12;
                len -= 12;
            }
            c += (UInt32)length;
            switch (len)
            {
                case 11:
                    c += (UInt32)(url[k + 10] << 24);
                    goto case 10;
                case 10:
                    c += (UInt32)(url[k + 9] << 16);
                    goto case 9;
                case 9:
                    c += (UInt32)(url[k + 8] << 8);
                    goto case 8;
                case 8:
                    b += (UInt32)(url[k + 7] << 24);
                    goto case 7;
                case 7:
                    b += (UInt32)(url[k + 6] << 16);
                    goto case 6;
                case 6:
                    b += (UInt32)(url[k + 5] << 8);
                    goto case 5;
                case 5:
                    b += (UInt32)(url[k + 4]);
                    goto case 4;
                case 4:
                    a += (UInt32)(url[k + 3] << 24);
                    goto case 3;
                case 3:
                    a += (UInt32)(url[k + 2] << 16);
                    goto case 2;
                case 2:
                    a += (UInt32)(url[k + 1] << 8);
                    goto case 1;
                case 1:
                    a += (UInt32)(url[k + 0]);
                    break;
                default:
                    break;
            }
            Hashing(ref a, ref b, ref c);
            return string.Format("6{0}", c);
        }
        public int MyPageRank(string MyUrl)
        {
            string HashDomain = PerfectHash(MyUrl);
            string RequestedURL = string.Format("http://toolbarqueries.google.com/" +
                   "tbr?client=navclient-auto&ch={0}&features=Rank&q=info:{1}",
                   HashDomain, MyUrl);
            try
            {
                HttpWebRequest HttpRequest = (HttpWebRequest)WebRequest.Create(RequestedURL);
                string GetResponse = new StreamReader(
                       HttpRequest.GetResponse().GetResponseStream()).ReadToEnd();
                if (GetResponse.Length == 0)
                    return 0;
                else
                    return int.Parse(Regex.Match(GetResponse,
                           "Rank_1:[0-9]:([0-9]+)").Groups[1].Value);
            }
            catch (Exception)
            {
                return -1;
            }
        }
    }
}
Step 5
Now run website and type any url in  textbox then after click on "FindRank".
Result-Asp.net.png

Friday, April 19, 2013

Create And Delete Directory or Folder in ASP.NET


Introduction
In this article I will explain how to create and delete a directory or folder from your drive in ASP.NET using C#.When you are running a community website where the user posts articles, forum messages etc. When a user registers in a web site a folder can be created at run time, then when you upload or ask a query, the data can be automatically placed inside the user's own directory instead of the root or anywhere else. You must import the following namespace:
using System.IO;
Complete Program
Create_and_Remove_Directory.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;     // Add Namespace

public partial class Create_and_Remove_Directory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void RadButton1_Click(object sender, EventArgs e)
    {
        string path = @"D:\" + txtname.Text;  // Give the specific path
        if (!(Directory.Exists(path)))
        {
            Directory.CreateDirectory(path);
            Sucesslbl.Text = "Directory Created Successfully";
        }
        else
        {
            Sucesslbl.Text = "Already Directory Exits With Same Name";
        }
    }
    protected void RadButton2_Click(object sender, EventArgs e)
    {
        string path = @"D:\" + deletetxt.Text;
        if (Directory.Exists(path))
        {
            DeleteDirectory(path);
        }
        else
        {
            Deletelbl.Text = "Directory not exits";
        }
    }
    private void DeleteDirectory(string path)
    {
        // Delete all files from the Directory
        foreach (string filename in Directory.GetFiles(path))
        {
            File.Delete(filename);
        }
        // Check all child Directories and delete files
        foreach (string subfolder in Directory.GetDirectories(path))
        {
            DeleteDirectory(subfolder);
        }
        Directory.Delete(path);
        Deletelbl.Text = "Directory deleted successfully";
    }
}

Create_and_Remove_Directory.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Create_and_Remove_Directory.aspx.cs"Inherits="Create_and_Remove_Directory" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width230px;
        }
        .style2
        {
            width169px;
        }
        .style3
        {
            width230px;
            height26px;
        }
        .style4
        {
            width169px;
            height26px;
        }
        .style5
        {
            height26px;
        }
        .style6
        {
            width230px;
            height29px;
        }
        .style7
        {
            width169px;
            height29px;
        }
        .style8
        {
            height29px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>  
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <h3>Create and Remove Directory in ASP.NET</h3>
        <table style="width: 47%;">
            <tr>
                <td class="style1" style="font-weight: bold">
                    Enter File Name to Create</td>
                <td class="style2">
                    <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                </td>
                <td class="style4">
                    <telerik:RadButton ID="RadButton1" runat="server" Font-Bold="True"
                        onclick="RadButton1_Click" Text="Create Directory">
                    </telerik:RadButton>
                </td>
                <td class="style5">
                    <asp:Label ID="Sucesslbl" runat="server" ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style6" style="font-weight: bold">
                    Enter File Name to Delete</td>
                <td class="style7">
                    <asp:TextBox ID="deletetxt" runat="server"></asp:TextBox>
                </td>
                <td class="style8">
                </td>
            </tr>
            <tr>
                <td class="style1">
                    &nbsp;</td>
                <td class="style2">
                    <telerik:RadButton ID="RadButton2" runat="server" Font-Bold="True"
                        onclick="RadButton2_Click" Text="Delete Directory">
                    </telerik:RadButton>
                </td>
                <td>
                    <asp:Label ID="Deletelbl" runat="server" ForeColor="Red"></asp:Label>
                </td>
            </tr>
        </table> 
    </div>
    </form>
</body>
</html>

Output 1
 first-image.jpg

Enter the directory name and then click on the "Create Directory" button:
 enter-directory-name.jpg

Output 2
If you will again click on Create Directory button then:
 re-click-on-create-directory.jpg
Output 3
Open the drive and you will see a new directory created, as in:
 create-directory-in-drive.jpg

Output 4
Now enter a name in the "remove" TextBox and then click on the "Delete Directory" button:
 click-on-delete-button.jpg

Output 5
If you will again click on Delete Directory button then:
 re-click-on-delete-button.jpg

Output 6
Now, open the drive, a new directory is removed from your drive, as in:
 remove-directory-from-drive.jpg

For more information, download the attached sample application.