Search This Blog

Tuesday, September 17, 2013

PROCEDURE VS FUNCTION ORACLE

Differences between Stored Procedures and Functions

  • Procedure can return zero or n values whereas function can return one value which is mandatory.
  • Procedures can have input/output parameters for it whereas functions can have only input parameters.
  • Procedure allows select as well as DML statement in it whereas function allows only select statement in it.
  • Functions can be called from procedure whereas procedures cannot be called from function.
  • Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in afunction.
  • We can go for transaction management in procedure whereas we can't go in function.
  • Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.

In depth

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.

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.
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 re

Monday, September 16, 2013

CREATING CAB FILES IN .NET

Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.Deployment.Compression.Cab
Public Class Test

    Public Shared Sub Main()
        Dim path As String = "c:\Newfolder\MyTest.txt"

        ' Delete the file if it exists.
        If File.Exists(path) Then
            File.Delete(path)
        End If

        'Create the file.
        Dim fs As FileStream = File.Create(path)

        AddText(fs, "This is some text")
        AddText(fs, "This is some more text,")
        AddText(fs, Environment.NewLine & "and this is on a new line")
        AddText(fs, Environment.NewLine & Environment.NewLine)
        AddText(fs, "The following is a subset of characters:" & Environment.NewLine)

        Dim i As Integer

        For i = 1 To 120
            AddText(fs, Convert.ToChar(i).ToString())

        Next

        fs.Close()

        Dim __cab As CabInfo
        Dim list As New List(Of String)
        list.Add("c:\Newfolder\MyTest.txt")
        __cab = New CabInfo("c:\Newfolder\cab1.cab")
        __cab.PackFiles(Nothing, list, Nothing)
        ''Open the stream and read it back.
        'fs = File.OpenRead(path)
        'Dim b(1024) As Byte
        'Dim temp As UTF8Encoding = New UTF8Encoding(True)

        'Do While fs.Read(b, 0, b.Length) > 0
        '    Console.WriteLine(temp.GetString(b))
        'Loop

        'fs.Close()
    End Sub

    Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)
        Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
        fs.Write(info, 0, info.Length)
    End Sub
End Class

Monday, February 18, 2013

Dynamically Change CSS on Button Click in ASP.NET


This article will explain on how css can be changed dynamically on button click in asp.net

Introduction


Hello friends, in this article we will see how to change the CSS of asp.net application dynamically.
In this article, button is being used to change the CSS using the Button Click event.


Objective


There are lots of time we want to change the background dynamically and also the look and feel of the website and you regret using Themes because it only works for asp.net controls and not to HTML Controls.Hence we can use CSS. For simplicity asp.net controls are used in this article,however HTML controls can be used as well.

Using the code


We have 1 label and 2 buttons, The first button will change the background of the webpage to maroon color and font family and the look of the label as well and the second button will change the background color to yellow and the font and the labels look and feel as per CSS.

To work around we have to implement a default look and feel,hence for that i have kept the background color to aqua.so when the page will load for the first time it will have the look and feel of the default css and on button clicks it will change the css and apply the changes as per css rule.

Now to change the CSS dynamically on button click we will use the command argument value given to the button in HTML mark up.

The command argument is the name of the css with extension of the css as well.

In all the css i have a common class .label so that i can also change the look and the feel of the label as well as per the changing the css.

For this i have assigned .label class to the label control.

Make a note that the default.css should have the .label class so that you can apply the changes to the label.



************Using the code and understanding the code*************************

 id="lnkCSS" href="css/Default.css" runat="server" rel="stylesheet" type="text/css" /> 
The above line if you check i have set the runat = server mode to the link so that i can get this link on code behind to change its properties on code behind.

Block of code should be set style as "Code" like below.
// HTML Mark Up
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dymaic Change of Css.aspx.cs" Inherits="Dymaic_Change_of_Css" %>

 xmlns="http://www.w3.org/1999/xhtml">
 runat="server">
    
     id="lnkCSS" href="css/Default.css" runat="server" rel="stylesheet" type="text/css" />


    
id="form1" runat="server">    
    ID="lblseeEffect" runat="server" Text="This is a Label" CssClass="label"> /> />     ID="btnCss1" runat="server" CommandArgument="Brown.css"             Text="Apply Brown Theme" onclick="btnCss1_Click" />               ID="btnCss2" runat="server" CommandArgument="Yellow.css"             Text="Apply Yellow Theme" onclick="btnCss2_Click" />    

   
   



//Default.css
body {
        background-color:Aqua;
        font-family:@Adobe Gothic Std B;
        font-size:15pt;
}
.label{
    font-weight:bold;
    color:Red;
}
//Brown.css
body {
        background-color:Maroon;
        font-family:@GulimChe;
        }
.label{
    font-weight:bold;
    color:Yellow;
    font-size:20pt;
}
Yellow.css
body {
        background-color:Yellow;
        font-family:Adobe Caslon Pro Bold;
}
.label{
        color:Maroon;
        font-size:15pt;
        }
//Code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Dymaic_Change_of_Css : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnCss1_Click(object sender, EventArgs e)
    {
        lnkCSS.Attributes["href"] = "~/css/" + (sender as Button).CommandArgument; // this will change the css as per the command agruement given in the HTML mark up
    }
    protected void btnCss2_Click(object sender, EventArgs e)
    {
        lnkCSS.Attributes["href"] = "~/css/" + (sender as Button).CommandArgument;// this will change the css as per the command agruement given in the HTML mark up

    }
}

Friday, July 1, 2011

Option statements in vb.net

Option Infer Statement


Enables the use of local type inference in declaring variables.

Option Infer { On | Off }

To set Option Infer in a file, type Option Infer On or Option Infer Off at the top of the file, before any other source code. If the value set for Option Infer in a file conflicts with the value set in the IDE or on the command line, the value in the file has precedence.

When you set Option Infer to On, you can declare local variables without explicitly stating a data type. The compiler infers the data type of a variable from the type of its initialization expression.

In the following illustration, Option Infer is turned on. The variable in the declaration Dim someVar = 2 is declared as an integer by type inference.

IntelliSense when Option Infer is on

IntelliSense view of the declaration.

In the following illustration, Option Infer is turned off. The variable in the declaration Dim someVar = 2 is declared as an Object by type inference. In this example, the Option Strict setting is set to Off on the Compile Page, Project Designer (Visual Basic).

IntelliSense when Option Infer is off

IntelliSense view of the declaration.

When a variable is declared as an Object, the run-time type can change while the program is running. Visual Basic performs operations called boxing and unboxing to convert between an Object and a value type. These operations make execution slower. For information about boxing and unboxing, see the Visual Basic Language Specification.

Type inference applies at the procedure level, and does not apply outside a procedure in a class, structure, module, or interface.



Option Compare Statement


Declares the default comparison method to use when comparing string data.

Option Compare { Binary | Text } 

Term

Definition

Binary

Optional. Results in string comparisons based on a sort order derived from the internal binary representations of the characters.

This type of comparison is useful especially if the strings can contain characters that are not to be interpreted as text. In this case, you do not want to bias comparisons with alphabetical equivalences, such as case insensitivity.

Text

Optional. Results in string comparisons based on a case-insensitive text sort order determined by your system's locale.

This type of comparison is useful if your strings contain all text characters, and you want to compare them taking into account alphabetic equivalences such as case insensitivity and closely related letters. For example, you might want to consider A and a to be equal, and Ä and ä to come before B and b.

If used, the Option Compare statement must appear in a file before any other source code statements.

The Option Compare statement specifies the string comparison method (Binary or Text). The default text comparison method is Binary.

A Binary comparison compares the numeric Unicode value of each character in each string. A Text comparison compares each Unicode character based on its lexical meaning in the current culture.

In Microsoft Windows, sort order is determined by the code page. For more information, see Code Pages.

In the following example, characters in the English/European code page (ANSI 1252) are sorted by using Option Compare Binary, which produces a typical binary sort order.

A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø

When the same characters in the same code page are sorted by using Option Compare Text, the following text sort order is produced.

(A=a) < (À = à) < (B=b) < (E=e) < (Ê = ê) < (Z=z) < (Ø = ø)

Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Object type.


Option Strict Statement

Option Strict { On | Off } 

Term

Definition

On

Optional. Enables Option Strict checking.

Off

Optional. Disables Option Strict checking. If On or Off is not specified, the default is Off.

When Option Strict On or Option Strict appears in a file, the following conditions cause a compile-time error:

  • Implicit narrowing conversions

  • Late binding

  • Implicit typing that results in an Object type



Option Explicit Statement (Visual Basic)

Forces explicit declaration of all variables in a file, or allows implicit declarations of variables.

Option Explicit { On | Off } 
On

Optional. Enables Option Explicit checking. If On or Off is not specified, the default is On.

Off

Optional. Disables Option Explicit checking.


Friday, August 13, 2010

configure audit policy

Auditpol


This command is new to Windows Server 2008 and Vista and is required for querying or configuring audit policy at the subcategory level. Before using this command to configure subcategories make sure you enable "Audit: Force audit policy subcategory settings (Windows Vista or later) to override audit policy category settings".

This command is the only way you can configure audit policy at the subcategory level (Group Policy only allows you to configure audit policy at the category level). Furthermore auditpol does not accept a computer name for remotely configuring audit policy on another computer on the network; instead you must execute auditpol locally on each system.

To see the full syntax for this command run "auditpol /?" at the command line.

To get a listing of all categories and their subcategories, run:

auditpol /list /subcategory:*

To display the current audit policy for all subcategories run:

auditpol /get /category:*

Here's an example of enabling the File System subcategory for success and failure:

AUDITPOL /SET /SUBCATEGORY:"file system" /SUCCESS:ENABLE /FAILURE:ENABLE

SET ADMIN ONLY ACCESS PERMISSION ON A FILE

namespace PermissionTest
{

public class PermissionControl
{
List usernames = new List();
List adminusers = new List();
string file_path = "C:\\TEXT1.txt";
public PermissionControl()
{
try
{
GetALLUsersList();
Load_Admin_Users();
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
RemoveAccess(file_path);
}
// -- this function all the users of the system on the generic list --
private void GetALLUsersList()
{
DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
foreach (DirectoryEntry child in directoryEntry.Children)
{
if (child.SchemaClassName == "User")
{
usernames.Add(child.Name);
}

}


}
// -- this function admin users of the system on the generic list --
private void Load_Admin_Users()
{
using (DirectoryEntry groupEntry = new DirectoryEntry("WinNT://./Administrators,group"))
{
foreach (object member in (IEnumerable)groupEntry.Invoke("Members"))
{
using (DirectoryEntry memberEntry = new DirectoryEntry(member))
{
adminusers.Add(memberEntry.Name);
//Console.WriteLine(memberEntry.Name);
}
}
}
//Console.ReadKey();
}

//--- this method is used to remove access of non admin users on a file --
private void RemoveAccess(string FilePath)
{
try
{
FileSecurity fs = File.GetAccessControl(FilePath);


foreach (string uname in usernames)
{
if (adminusers.Contains(uname) == false)
{
try
{
fs.AddAccessRule(new FileSystemAccessRule(System.Environment.UserDomainName + "\\" + uname, FileSystemRights.FullControl, AccessControlType.Deny));
File.SetAccessControl(FilePath, fs);
}
catch (System.Security.SecurityException se)
{
MessageBox.Show(se.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("Admin Permissions applied.", "Test");
// @System.Environment.UserDomainName\AccountName"



// "denied from FullControl access.");

}


}

static class Program
{
static string LogFile = Application.StartupPath + "\\LogFile.txt";
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new PermissionTest ());

// Execute the command synchronously.

// first of create a log file
if (!File.Exists(LogFile))
{
File.Create(LogFile);
}
PermissionControl p = new PermissionControl();

}

}
}

Friday, May 21, 2010

C# Indexers

C# introduces a new concept known as Indexerswhich are used for treating an object as an array. The indexers areusually known as smart arrays in C# community. Defining a C# indexer ismuch like defining properties. We can say that an indexer is a memberthat enables an object to be indexed in the same way as an array.

this [argument list]
{
get
{
// Get codes goes here
}
set
{
// Set codes goes here
}
}

Where the modifier can be private, public,protected or internal. The return type can be any valid C# types. The'this' is a special keyword in C# to indicate the object of the currentclass. The formal-argument-list specifies the parameters of theindexer. The formal parameter list of an indexer corresponds to that ofa method, except that at least one parameter must be specified, andthat the ref and out parameter modifiers are not permitted.Remember that indexers in C# must have at least one parameter. Otherwise the compiler will generate a compilation error.

The following program shows a C# indexer in action

// C#: INDEXER
// Author: rajeshvs@msn.com

using System;
using System.Collections;

class MyClass
{
private string []data = new string[5];
public string this [int index]
{
get
{
return data[index];
}
set
{
data[index] = value;
}
}
}

class MyClient
{
public static void Main()
{
MyClass mc = new MyClass();
mc[0] = "Rajesh";
mc[1] = "A3-126";
mc[2] = "Snehadara";
mc[3] = "Irla";
mc[4] = "Mumbai";
Console.WriteLine("{0},{1},{2},{3},{4}",mc[0],mc[1],mc[2],mc[3],mc[4]);
}
}

The indexers in C# can be overloaded just likemember functions. The formal parameter list of an indexer defines thesignature of the indexer. Specifically, the signature of an indexerconsists of the number and types of its formal parameters. The elementtype is not part of an indexer's signature, nor is the names of theformal parameters. The signature of an indexer must differ from thesignatures of all other indexers declared in the same class. C# do nothave the concept of static indexers. If we declare an indexer static,the compiler will show a compilation time error.

Indexers & Inheritance

Just like any other class members, indexerscan also participate in inheritance. A base class indexer is inheritedto the derived class.

//C#: Indexer : Inheritance
//Author: rajeshvs@msn.com
using System;
class Base
{
public int this[int indxer]
{
get
{
Console.Write("Base GET");
return 10;
}
set
{
Console.Write("Base SET");
}
}
}

class Derived : Base
{

}
class MyClient
{
public static void Main()
{
Derived d1 = new Derived();
d1[0] = 10;
Console.WriteLine(d1[0]);//Displays 'Base SET Base GET 10'
}
}

Indexers & Polymorphism

A Base class indexer can be polymorphicalyoverridden in a Derived class. But remember that the modifiers likevirtual, override etc are using at property level, not at accessorlevel.

//C#: Indexer : Polymorphism
//Author: rajeshvs@msn.com

using System;

class Base
{
public virtual int this[int index]
{
get
{
Console.Write("Base GET");
return 10;
}
set
{
Console.Write("Base SET");
}
}
}

class Derived : Base
{
public override int this[int index]
{
get
{
Console.Write("Derived GET");
return 10;
}
set
{
Console.Write("Derived SET");
}
}
}

class MyClient
{
public static void Main()
{
Base b1 = new Derived();
b1[0]= 10;
Console.WriteLine(b1[0]);//Displays 'Derived SET Derived GET 10'
}
}

Abstract Indexers

An indexer inside a class can be declared asabstract by using the keyword abstract. Remember that an abstractindexer in a class carries no code at all. The get/set accessors aresimply represented with a semicolon. In the derived class we mustimplement both set and get assessors.

If the abstract class contains only set accessor, we can implement only set in the derived class.

The following program shows an abstract indexer in action.

//C#: Indexer : Abstract
//Author: rajeshvs@msn.com

using System;

abstract class Abstract
{
public abstract int this[int index]
{
get;
set;
}
}

class Concrete : Abstract
{
public override int this[int index]
{
get
{
Console.Write(" GET");
return 10;
}
set
{
Console.Write(" SET");
}
}
}

class MyClient
{
public static void Main()
{
Concrete c1 = new Concrete();
c1[0] = 10;
Console.WriteLine(c1[0]);//Displays 'SET GET 10'
}
}



Indexers & Properties

1. An index is identified by it's signature. But a property is identified it's name.
2. An indexer is always an instance member, but a property can be static also.
3. An indexer is accessed through an element access. But a property is through a member access.