-->

Monday, February 24, 2014

How to Identify the Database Files in SQL Server

In SQL Server programming context, each database is stored as a set of files on the hard disk of the computer. These files may be of following types including

Primary data file

The primary data file contains the database objects. The primary file can be used for the system tables and objects, and the secondary file can be used to store user data and objects. The primary data file has (.mdf) extension.

Secondary data file

The secondary data file also stores the database objects. Very large databases may need multiple secondary data files spread across multiple disks. Databases need not have secondary data files, if the primary data file is large enough to hold all the data in the database. The secondary data file has (.ndf) extension.

Transaction log file

The transaction log file records all modifications that have occurred in the database and the transactions that caused those modifications. At least one transaction log file holds all the transaction’s information and can be used to recover a database. At least one transaction log file must exist for a database. There can be more than one transaction log file. The minimum size of a transaction log file is 512K. The size of the transaction log file should be 25 – 40 percent of the size of the database. The log file have an (.Idf) extension.
A database must consist of a primary data file and one transaction log file.
The database files are stored in filegroups. A filegroup is a collection of files. A database comprises a primary filegroup and any user-defined filegroup. A primary filegroup contains the primary data file and any other files that are not put into any other filegroup. The primary filegroup also contains the system database. When objects are created in the database without specifying the filegroup, they are assigned to the default filegroup. Only one filegroup in a database can be the default filegroup.

A user-defined filegroup is a filegroup that is created by users. You can create filegroups to distribute the data amongst more than one filegroups to improve the performance of database.

Sunday, February 23, 2014

Print one month later date in ASP.NET

You can use DateTime class for add months in current object of DateTime. DateTime class provides different types of methods to add this types of query like AddDays(), AddMonths() etc. This example cover AddMonth. Now take an simple example for that.

Complete Code 

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Label ID="Label1" runat="server"></asp:Label>
    
    </div>
    </form>
</body>
</html>
//code file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime d1 = new DateTime();
        Label1.Text += d1.ToLongDateString() + "<br/>";
        DateTime onemonthlater= d1.AddMonths(1);
        Label1.Text += onemonthlater.ToString()+ "<br/>";

        TimeSpan difference = onemonthlater - d1;
        Label1.Text += "difference in days" + difference.Days;

    }
}

Output
Print one month later date in ASP.NET


Doubly Linked List for Data Structure in C Programming

Doubly Linked List:

 A little more variation to linear linked list gives another type of linked list called as doubly linked list. You might have observed in the linear list that every node contains two parts. One part contains the information and the other part contains the address of the next node in the list. If another pointer part is added to the node, to contain the address of previous node then the linear linked list becomes doubly linked list. In such lists you can traverse only in one direction. In the middle of traverse if you want to come back to the previous node it is not possible. The movement is one-way. It is possible to move in both the directions in doubly linked list. You can traverse in both the directions. This application of variation is very simple. The node in doubly linked list looks as follows:


If the node is the first node of the list been previous pointer contains a NULL address because there are no previous nodes. If the node is the last node then next pointer contains a NULL address because there are no next nodes. A simple representation of doubly linked list is as follows:


In the above doubly linked list, ROOT, the external pointer points to the first node with information 12. The first node’s previous pointer points to NULL. The first node’s next pointer points to the second node with information 15. The second node’s previous pointer points to the previous node containing information 15. The last node’s next pointer points to NULL address. Creation of doubly linked list is almost similar to singly linked list. Only addition is assigning the previous pointer of every node except the first node, with the address of the previous node. The operations like traversing, searching, insertion and deletion are almost similar to singly linked list. While traversing the operation can be reversed from any point in the doubly linked list. While insertion and deletion the operations are similar to singly linked list except the change in previous as well as next pointer values.

Algorithm to create a doubly linked list:

CREATEDLL
ROOT<--NULL; CHOICE<--‘Y’
Repeat While CHOICE=’Y’
 If AVAIL = NULL Then:
  Write: ’Memory Allocation Error’ 
  Exit.
Else 
NEW<--AVAIL;   NEW-->LINK<--NULL
NEW-->PREV<--NULL;   NEW-->INFO<--Information
[Information is the data to be stored in linked list]
AVAIL<--AVAIL-->LINK
[End of it]
If ROOT=NULL Then:
   ROOT<--NEW;   TEMP<--NEW
Else 
TEMP-->LINK<--NEW;     NEW-->PREV<--TEMP
TEMP<--NEW
[End of If]
Write: ‘Do you want to add another node?(Y/N)’
 Read: CHOICE
[End of while]

Saturday, February 22, 2014

Searching In Circular linked list for Data Structure in 'C'

Searching:

               In order to do searching in circular linked list, get the information to be searched and set PTR with ROOT. Compare Information with INFO of PTR, if it is equal ‘search is successful’ and terminate operation otherwise update PTR with LINK of PTR and repeat the process. Continue the operation till the end. The end is recognized by an address of first node given by ROOT stored in Link of PTR.

Algorithm for searching:

       SEARCHCLL(ROOT, IN)
       [ROOT is starting address of Linked List and
         IN is Information to search in Linked List]
        PTR<--ROOT
        If PTR = NULL Then:
         Write: ‘Empty Circular linked list’
         Exit.
        [End of If]
        Repeat While IN< >PTR-->INFO
         If PTR-->LINK = ROOT Then:
            Break
         [End of If]
         PTR<--PTR-->LINK
         [End of while]
         If PTR-->INFO = IN Then:
           Write: ‘Search Successful’
         Else:
          Write: ‘Search Unsuccessful’
         [End of If]
         Exit.

The insertion and deletion operations in circular linked list are similar to that of linear linked list and they are left as exercise. The hint is to only replace the end node checking condition of the linear linked list with that of circular linked list. This condition replacement you have learned in traversing and searching in circular linked list.

Friday, February 21, 2014

Understanding traversing in circular linked list for Data Structure in 'C


Understanding traversing in circular linked list:

Let us consider the following circular linked list.

Let us assign a pointer PTR with ROOT, address of the first node. PTR is not equal to NULL. So, the circular linked list is not empty.

Repeat while TRUE

                Write: PTR-->INFO    i.e. 6 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK     Now PTR points to second node
                Write: PTR-->INFO     i.e. 16 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK       Now PTR points to third node
                Write: PTR-->INFO        i.e.  1 is written
                PTR-->LINK is not equal to ROOT. So, no break.
                PTR<--PTR-->LINK        Now PTR points to third node
               Write: PTR-->INFO         i.e. 61 is written
               PTR-->LINK is equal to ROOT. So, break.
The infinite loop breaks. So, the traversing is complete.

C Program to create and traverse Circular linked list:

     struct node
    {
      int info; struct node*link;
    };
    typedef struct node sn;
    main( )
    {
     sn *root,*temp,*new; char choice=’y’;
     root=NULL;
     clrscr( );
     while (choice==’y’)
     {
      new=(sn*)mallloc(sizeof(sn));
      if(new==NULL)
       {
        printf(“Memory allocation error…”); exit(0);
       }
        printf(“\nEnter node information:”);
        scanf(“%d”,&new->info);
        if(root==NULL)
        {
         root=new;     temp=root;
         }
        else
        {
         temp->link=new;   temp=new;
         }
       new->link=root;
       printf(“Do you want to continue…(y/n)”);
       choice=getche( );
     } /* end of while */
     printf(“\nThe Circular Linked list is:\n\n”);
     temp=root;
     while(1)
      {
       printf(“%d”,temp->info);
       if(temp->link==root)  break;
       temp=temp->link;
      }
     }      /* end of main( )*/


How to use Editor Ajax Control in ASP.NET

Editor control is a editor or you can say modifier, as a name suggest you can format article like bold.

How to use Editor 

Step-1 : Add Script Manager Control to the design page
Step-2 : Add Editor control to the page.
Step-3 : Add one button control also handle button_click event.

Code View

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">


    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <br />
    <cc1:Editor ID="Editor1" runat="server" Height="300px" Width="300px" />
    <p>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save " 
            Width="111px" />
    </p>


    </form>
</body>
</html>

Code Generate the following output

How to use Editor Ajax Control in ASP.NET

Thursday, February 20, 2014

Retrieve Record from Database using QueryString Parameter in ASP.NET

In my previous article, we already covered query string concepts. In this article, we will cover how to get record from database using query string parameter. For this types of problem, we will take two webform, first webform is used for sending querystring and pass into second web form.

Design pattern

Step-1 : Take two Web Form in solution explorer (default.aspx, default2.aspx)
Step-2 :  Bind GridView on first page (default.aspx page) using SqlDataSource control.
Step-3 : Check "select checkbox using show smart tag.
Step-4 : Handle GridView SelectedIndexChanged event , also generate QueryString in it. look like



protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("~/Default2.aspx?id=" + GridView1.SelectedRow.Cells[1].Text);
    }


Step-5 : In second page( Default2.aspx), Bind form view using SqlDataSource with Query String parameter.

Retrieve Record from Database using QueryString Parameter in ASP.NET

Retrieve Record from Database using QueryString Parameter in ASP.NET

Code view 

Default.aspx with Default.aspx.cs page

<%@ 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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT * FROM [usertable]"></asp:SqlDataSource>
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="id" DataSourceID="SqlDataSource1" 
        onselectedindexchanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                ReadOnly="True" SortExpression="id" />
            <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
            <asp:BoundField DataField="address" HeaderText="address" 
                SortExpression="address" />
        </Columns>
    </asp:GridView>
    </form>
</body>
</html>

// Code view

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("~/Default2.aspx?id=" + GridView1.SelectedRow.Cells[1].Text);
    }
}

Default2.aspx 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="id" 
            DataSourceID="SqlDataSource1" Height="174px" Width="158px">
            <EditItemTemplate>
                id:
                <asp:Label ID="idLabel1" runat="server" Text='<%# Eval("id") %>' />
                <br />
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                    CommandName="Update" Text="Update" />
                &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </EditItemTemplate>
            <InsertItemTemplate>
                name:
                <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:TextBox ID="addressTextBox" runat="server" Text='<%# Bind("address") %>' />
                <br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insert" />
                &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Cancel" />
            </InsertItemTemplate>
            <ItemTemplate>
                id:
                <asp:Label ID="idLabel" runat="server" Text='<%# Eval("id") %>' />
                <br />
                name:
                <asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>' />
                <br />
                address:
                <asp:Label ID="addressLabel" runat="server" Text='<%# Bind("address") %>' />
                <br />

            </ItemTemplate>
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT * FROM [usertable] WHERE ([id] = @id)">
            <SelectParameters>
                <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

Code Generate the following output

Retrieve Record from Database using QueryString Parameter in ASP.NET

Retrieve Record from Database using QueryString Parameter in ASP.NET

© Copyright 2013 Computer Programming | All Right Reserved