Wednesday, June 16, 2010

what is Sequences in oracle?

                                          Oracle provides an object called a sequence that can generate numeric value.The value generated can have a maxiumum of 38 digit.A sequence can be used to auto generate numeric value.The value generated can have a maximum of 38 digit.
A sequence can be defined to
* Generate number in ascending order or desending order.
* Provide intervals between number .
* Caching of sequence number in memory etc.
The minimum information required for generating numbers using sequence is:-
* The Starting number .
* maximum number that can be generated by a sequence.
*increment value for generating the next number.
                   All this info is provided to oracle at the time of sequence creation .The sql statement used for creating sequence is:-
syntax:-

create sequence sequence_name
[ increment by integer value
  start with integer value
  maxvalue integer value
  minvalue  integer value
  cycle/nocycle
  cache/nocache inter value
 order/noorder ]

Thursday, June 10, 2010

use of sessions in asp.net?

Sessions can be used to store even complex data for the user just like cookies. Actually, sessions will use cookies to store the data, unless you explicitly tell it not to. Sessions can be used easily in ASP.NET with the Session object.
Keep in mind though, that sessions will expire after a certain amount of minutes, as configured in the web.config file. Markup code:-
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Sessions</title>
</head>
<body runat="server" id="BodyTag">
    <form id="form1" runat="server">
    <asp:DropDownList runat="server" id="ColorSelector" autopostback="true" onselectedindexchanged="ColorSelector_IndexChanged">
        <asp:ListItem value="White" selected="True">Select color...</asp:ListItem>
        <asp:ListItem value="Red">Red</asp:ListItem>
        <asp:ListItem value="Green">Green</asp:ListItem>
        <asp:ListItem value="Blue">Blue</asp:ListItem>
    </asp:DropDownList>
    </form>
</body>
</html>
/////////////////////////////////////////////////////////////////////////////////////////// 
codebehind:-
////////////////////////////////////////////////////////////////////////////////////////// 
using System;using System.Data;using System.Web;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["BackgroundColor"] != null)
        {
            ColorSelector.SelectedValue = Session["BackgroundColor"].ToString();
            BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
        }
    }

    protected void ColorSelector_IndexChanged(object sender, EventArgs e)
    {
        BodyTag.Style["background-color"] = ColorSelector.SelectedValue;
        Session["BackgroundColor"] = ColorSelector.SelectedValue;
    }
}
///////////////////////////////////////////////////////////////////////////////////////////
web config:-
////////////////////////////////////////////////////////////////////////////////////////// 
<?xml version="1.0"?>
<!--
    Note: As an alternative to hand editing this file you can use the
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in
    machine.config.comments usually located in
    \Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
        <!--
            Set compilation debug="true" to insert debugging
            symbols into the compiled page. Because this
            affects performance, set this value to true only
            during development.
        -->
        <compilation debug="false" />
        <!--
            The <authentication> section enables configuration
            of the security authentication mode used by
            ASP.NET to identify an incoming user.
        -->
        <authentication mode="Windows" />
        <!--
            The <customErrors> section enables configuration
            of what to do if/when an unhandled error occurs
            during the execution of a request. Specifically,
            it enables developers to configure html error pages
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
      <sessionState mode="InProc" stateNetworkTimeout="1" sqlCommandTimeout="3" cookieName="ASP.NET_SessionId" timeout="1" regenerateExpiredSessionId="False">
        <providers>
          <clear/>
        </providers>
      </sessionState>
    </system.web>
  
</configuration>
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
session values are tied to an instance of your browser. If you close down the browser, the saved value(s) will usually be "lost". Also, if the webserver recycles the aspnet_wp.exe process, sessions are lost, since they are saved in memory as well. This can be avoided by saving session states on a separate StateServer or by saving to a SQL server

Wednesday, June 9, 2010

cache-output cache

we will take a look at the OutputCache directive, which is by far the easiest way of caching content with ASP.NET. As you will see in our example, it doesn’t even require any code – only some minor changes to the markup of the page, and you’re good to go. In the next chapter, we will look into more ways of using the OuputCachce directive.

Here is a very simple example of a page which will show us the difference between a cached page and a non-cached page. Try creating a new project, and change the Default.aspx page to contain the following markup:-
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>Caching</title>
</head>
<body>
    <form id="form1" runat="server">
        <%= DateTime.Now.ToString() %>
    </form>
</body>
</html>
/////////////////////////////////////////////////////////////////////////////////////
This is all standard stuff, except the line with the DateTime. It simply outputs the current date and time to the page. Try running the project and reload the page a couple of times. As you will see, the time is refreshed on each reload. Now, add the following line as line number 2 to our example:-
<%@ OutputCache duration="10" varybyparam="None" %>
 
Run our project again, and reload the page a number of times. As you will see, the time is only refreshed every 10 seconds. Adding caching to your page is as simple as that! Now, the duration parameter is pretty obvious - it tells the page how many seconds to cache the content. Each time the page is requested, ASP.NET checks if the page is in the cache, and if it is, whether or not it has expired. It's served from the cache if it isn't expired - if it is, the page is removed from the cache and the page is generated from scratch and then placed in the cache. 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The varybyparam is a required parameter of the OutputCache directive. It specifies a list of parameters which the the cache should be varied by. For instance, if you set it to "p", the cache is now depending on the value of the parameter p. Try changing our example to something like this:-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ OutputCache duration="10" varybyparam="p" %>
<!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>Caching</title>
</head>
<body>
    <form id="form1" runat="server">
        <%= DateTime.Now.ToString() %><br />
        <a href="?p=1">1</a><br />
        <a href="?p=2">2</a><br />
        <a href="?p=3">3</a><br />
    </form>
</body>
</html>
Now, run our example again, and try clicking the links. They each now have their own timestamp, based on when you first accessed the page. The cache is depending on the value of the p parameter! You can specify multiple parameters by seperating them with a semicolon.


What is ViewState?with example

Another approach to saving data for the user, is the ViewState. As described elsewhere in this tutorial, the ViewState allows ASP.NET to repopulate form fields on each postback to the server, making sure that a form is not automatically cleared when the user hits the submit button. All this happens automatically, unless you turn it off, but you can actually use the ViewState for your own purposes as well. Please keep in mind though, that while cookies and sessions can be accessed from all your pages on your website, ViewState values are not carried between pages. Here is a simple example of using the ViewState to carry values between postbacks:- 
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>ViewState</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:TextBox runat="server" id="NameField" />
        <asp:Button runat="server" id="SubmitForm" onclick="SubmitForm_Click" text="Submit & set name" />
        <asp:Button runat="server" id="RefreshPage" text="Just submit" />
        <br /><br />
        Name retrieved from ViewState: <asp:Label runat="server" id="NameLabel" />
    </form> </body>
</html>
///codebehind//
using System;using System.Data;using System.Web;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(ViewState["NameOfUser"] != null)
            NameLabel.Text = ViewState["NameOfUser"].ToString();
        else
            NameLabel.Text = "Not set yet...";
    }

    protected void SubmitForm_Click(object sender, EventArgs e)
    {
        ViewState["NameOfUser"] = NameField.Text;
        NameLabel.Text = NameField.Text;
    }
}
Try running the project, enter your name in the textbox and press the first button. The name will be saved in the ViewState and set to the Label as well. No magic here at all. Now press the second button. This one does nothing at all actually, it just posts back to the server. As you will notice, the NameLabel still contains the name, but so does the textbox. The first thing is because of us, while the textbox is maintained by ASP.NET it self. Try deleting the value and pressing the second button again. You will see that the textbox is now cleared, but our name label keeps the name, because the value we saved to the ViewState is still there!

ViewState is pretty good for storing simple values for use in the form, but if you wish to save more complex data, and keep them from page to page, you should look into using cookies or sessions

what is Inheritance?with Example

One of the absolute key aspects of Object Oriented Programming (OOP), which is the concept that C# is built upon, is inheritance, the ability to create classes which inherits certain aspects from parent classes. The entire .NET framework is built on this concept, with the "everything is an object" as a result of it. Even a simple number is an instance of a class, which inherits from the System.Object class, although .NET helps you out a bit, so you can assign a number directly, instead of having to create a new instance of e.g. the integer class.

This subject can be a bit difficult to comprehend, but sometimes it help with some examples, so let's start with a simple one of those:-
public class Animal
{
    public void Greet()
    {
        Console.WriteLine("Hello, I'm some sort of animal!");
    }
}
 
public class Dog : Animal
{

}
//
First, we define an Animal class, with a simple method to output a greeting. Then we define a Dog class, and with a colon, we tell C# that the Dog class should inherit from the Animal class. The beautiful thing about this is that it makes sense in the real world as well - a Dog is, obviously, an Animal. Let's try using the classes:-
Animal animal = new Animal();
animal.Greet();
Dog dog = new Dog();
dog.Greet();
////
If you run this example, you will notice that even though we have not defined a Greet() method for the Dog class, it still knows how to greet us, because it inherits this method from the Animal class. However, this greeting is a bit anonymous, so let's customize it when we know which animal it is:-
public class Animal
{
    public virtual void Greet()
    {
        Console.WriteLine("Hello, I'm some sort of animal!");
    }
}
public class Dog : Animal
{
    public override void Greet()
    {
        Console.WriteLine("Hello, I'm a dog!");
    }
}
///
Besides the added method on the Dog class, you should notice two things: I have added the virtual keyword to the method on the Animal class, and on the Dog class, I use the override keyword. In C#, you are not allowed to override a member of a class unless it's marked as virtual. If you want to, you can still access the inherited method, even when you override it, using the base keyword. 
public override void Greet()
{
    base.Greet();
    Console.WriteLine("Yes I am - a dog!");

}
//
Methods is not the only thing to get inherited, though. In fact, pretty much all class members will be inherited, including fields and properties. Just remember the rules of visibilty, as discussed in a previous chapter.

Inheritance is not only from one class to another - you can have a whole hierarchy of classes, which inherits from eachother. For instance, we could create a Puppy class, which inherits from our Dog class, which in turn inherits from the Animal class. What you can't do in C#, is to let one class inherit from several other classes at the same time. Multiple inheritance, as it's called, is not supported by C#.

Tuesday, June 8, 2010

Base class of .net?

System.Object is the base class of .NET.
                                  It Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate superclass of all classes in the .NET Framework; it is the root of the type hierarchy.
                                                     Base class is a root class or superior class from which we can extend classes.it is the topmost in the classes so other classes can be derived from this class but it is not derived from any class.Depending on procedure base class may or may not give its objects to derived classes of it. 
system.Web.UI is for asp.net

The super most base class is system.object. even the system.web.ui comes from the system.object. All the object of type either value or reference type come from system.object. see the msdn doc for the same.

What is ViewState?

"When a form is submitted in classic ASP, all form values are cleared. Suppose you have submitted a form with a lot of information and the server comes back with an error. You will have to go back to the form and correct the information. You click the back button, and what happens.......ALL form values are CLEARED, and you will have to start all over again! The site did not maintain your ViewState".

When a form is submitted in ASP .NET, the form reappears in the browser window together with all form values. How come? This is because ASP .NET maintains your ViewState. The ViewState indicates the status of the page when submitted to the server. The status is defined through a hidden field placed on each page with a <form runat="server"> control. The source could look something like this:-

<form name="_ctl0" method="post" action="page.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE"
value="tyujfghjbcde+hjgfkghyrhrjr=" />SOME CODE here</form>

Monday, June 7, 2010

Many‑to‑Many (M:M)








A many-to-many relationship between two entities indicates that either entity participating in the relationship may occur one or several times.

One‑to‑Many (1:M), Many‑to‑One (M:1)










A one-to-many or a many-to-one relationship between two entities indicates that a single occurrence of one entity is associated with one or more occurrences of the related entity.

One-to-One (1:1)

A one-to-one relationship between two entities indicates that each occurrence of one entity in the relationship is associated with a single occurrence in the related entity.

There are three types of relationship cardinality.


one-to-one.
one-to-many.
many-to-many.

Types of Relationship Combinations

"Entities are often involved in a variety of relationships. Optional relationships are often affected by the existence of another relationship". Clarify the nature of two or more relationships concerned with a particular entity by one of the following combinations:-
  • inclusive OR (either or both).
  • exclusive OR (either, but not both).
  • AND (both must exist).
Inclusive OR -An inclusive OR relationship indicates that entity A is related to either entity B or entity C or both B and C.
Exclusive OR- An exclusive OR relationship indicates that entity A is related to either entity B or entity C but not both B and C.
AND -An AND relationship indicates that entity A is related to both entity B and entity C.

Data Flow Diagrams (DFD) :-Level2/Low level Diagram

This level2 is decomposition of a process shown in a level-1 diagram, as such there should be a level-2 diagram for each and every process shown in a level-1 diagram.

Data Flow Diagrams (DFD) :-Level 1/High Level Diagram

















  • This level (level 1) shows all processes at the first level of numbering, data stores, external entities and the data flows between them. The purpose of this level is to show the major high-level processes of the system and their interrelation.

Data Flow Diagrams (DFD) :-Level 0/Context diagram



                                                                                                       




       








A context diagram is constructed that shows only a single process(representing the entire system) , and associated external entities and no data stores.

Defining DFD Components

DFDs consist of four basic components:-
Entity:- An entity is the source or destination of data. Entities either provide data to the system or receive data from it. Entities are often represented as rectangles.










Process: -
The process is the manipulation or work that transforms data, performing computations, making decisions (logicflow), or directing data flows based on business rules. In other words, a process receives input and generates some output. Processes can be drawn as circles or a segmented rectangle on a DFD, and include a process name and process number.









Data Store:- Collection of data that is pemanently stored. Data stores are usually drawn as a rectangle with the righthand side missing.



 

Data Flow:- Data flow is the movement of data between the entity,
the process, and the data store. Data flow is represented by an arrow,
where the arrow is annotated with the data name.

DFDs represent the following:-

    1.External devices sending and receiving data.
    2.Processes that change that data.
    3.Data flows themselves.
    4.Data storage locations.

Data Flow Diagrams (DFD)

A data flow diagram (DFD) is a graphical representation of the flow of data between processes. DFDs are used in the preliminary stages of systemsanalysis to help understand the current system and to represent a required system. Data flow diagrams (DFDs) are the method of choice over technical descriptions for three principal reasons:-
DFDs are easier to understand by technical andnontechnical audiences.
DFDs can provide a high level system overview, complete with boundaries and connections to other systems.
DFDs can provide a detailed representation of system components.

Application Architectures















§Three-tier architecture: E.g. web-based applications, and
  applications built using “middleware”
§Two-tier architecture:  E.g. client programs using ODBC/JDBC to 
  communicate with a database

E-R Diagram example2

E-R Diagram example1

E-R Diagram



An entity-relationship (ER) diagram is a specialized graphic that defines the interrelationships between entities in a database.
    Simple and easy to understand.
    •Showing the conceptual design of the database.
    •Shows the type of information that is to be stored in the system and how these information associate with each other (e.g. one-to-one, one-to-many, etc).
    Simple and easy to understand.