Monday, 6 May 2013

Query String Parameters

Query String parameters to pass values from one page to another page. Query string parameters are created by using ? symbol at the end of the url while navigating to a page. Next to the ? symbol, specify the parameter name followed by= operator  followed by the value to pass using that parameter. When, you have multiple parameters then seperate them with & symbol.

Server.Trnasfer("~/page2,aspx? pname=value& pname=value");

To read query string parameters, use QueryString property of Request object.

Varname=Request.QueryString["pname"];

Saturday, 4 May 2013

Crystal Reports

         Crystal Reports is a business intelligence application used to design and generate reports from a wide range of data sources. Several other applications, such as Microsoft Visual Studio bundle and OEM version of Crystal Reports as a general purpose reporting tool. Crystal Reports become the de facto standard report writer when Microsoft released it with Visual Studio.
       The product was originally created by crystal services Inc. as Quik reports when they could  not find a suitable commercial report writer for their accounting software. After producing versions 1.0 through 3.0, the company was acquired in 1994 by Seagate Technology. Crystal Services was combined with Holostic Systems to form the information group of Seagate software, which later rebranded as crystal decisions, and produced versions 4.0 through 9.0. Crystal decisions was acquired in December 2003 by business objects, which has so far produced versions 10, 11 and current version 12.
         

Wednesday, 1 May 2013

Session State Management

Session is a block of memory on server allocated separately for every user of the website and is used to store the data that is private to a particular user. For the applications like online shopping session state is required for storing items selected by the user in different pages and finally gets the list of session and prepares the bill

Session has the following advantages over Cookies
  • Session data is stored on server and then there will be security for the data. But cookies are stored on client system in plain text file and hence there is no security for the data.
  • Session can store any type of data whereas a cookie can store only standard type of data like int,float,double,string,date.
  • Session has no limit and you can store any type of data in the session whereas a cookie can store a maximum of only 4KB data and overall 80KB if the browser allows a maximum of 20 cookies per website.
  • Session state cant be disabled by an end user and hence the code within using session will work whereas cookies can b disables with end user in browser and hence there is no guarantee that your code that uses cookies will work.

Tuesday, 30 April 2013

State Management

Web and HTTP protocol are stateless. Hence server cant identify whether or not two requests came from same user and server will treat every request as the request from a new user. Because of the stateless nature of the web it is not possible to develop applications like shopping cart and implementing security in the websites. To overcome this problem, Asp.Net provides state management techniques. Client Side State Management techniques include Cookies, Viewstate and QueryString Parameters and Server side state management techniques include Session, Application and Caching.

 COOKIES

A cookie is a small amount of memory allocated on client system for storing personnel information about the client like remembering user id and password, making a count of failed login attempts, security and also session state management. To create a cookie use HttpCookie class and to assign a value to the cookie use its Value property and finally to store it in a client system call AppendCookie() method of Response object.

Sunday, 28 April 2013

Extensible Markup language (XML).

         XML Stands for Extensible Markup Language. Its a language much like HTML which was designed to carry data, not to display data and also self-descriptive. XML does not do anything. XML was created to structure,store and transport information. XML tags are not predefined, you must define your own tags. XML is not a replacement for HTML, HTML and XML were designed with different goals:
  • XML was designed to transport and store data, with focus on what data is.
  • HTML was designed to display data, with focus on how data looks.
  • HTML is about displaying information, while XML is about carrying information.
To create an XML document we need to satisfy a set of rules that are prescribed by W3C, as following
  • An XML doc has to be saved with .xml extention.
  • Data under XML doc should be present only under tags, where every tag should have a start and end element.       eg:   <Tag><Tag> Or <Tag id="1"/>
  • Tags can also be defined with attribute which are user-defined where value to attribute should be enclosed under double quotes.
  • While defining tags start and end tag should match in case.
  • An Xml doc can only have one root element.

Friday, 26 April 2013

Accessing MS Excel data from .Net Application

Ms Excel is a file system which stores data in the form of rows and columns same as a database table. An Excel document is referred as Work Book that contains Work Sheets in it, work books are considered as databases and work sheets are considered as tables.First row of work sheet can store column names.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace WinForms7
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }
        OdbcConnection con; OdbcCommand cmd; OdbcDataReader dr; string Sqlstr;
        private void Form6_Load(object sender, EventArgs e)
        {
            con = new OdbcConnection("Dsn=ExcelDsn; ReadOnly=0");
            cmd = new OdbcCommand();
            cmd.Connection = con;
            con.Open();
            LoadData();
            label1.Text = dr.GetName(0); label2.Text = dr.GetName(1);
            label3.Text = dr.GetName(2); label4.Text = dr.GetName(3);
               
        }
        private void LoadData()
        {
            cmd.CommandText = "Select * from[Student$]";
            cmd.ExecuteReader();
            ShowData();


        }
        private void ShowData()
        {
            if (dr.Read())
            {
                textBox1.Text = dr[0].ToString();
                textBox2.Text = dr[1].ToString();
                textBox3.Text = dr[2].ToString();
                textBox4.Text = dr[3].ToString();
            }
            else
                MessageBox.Show("No data exists");

               
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = textBox2.Text = textBox3.Text = textBox4.Text = " ";
            textBox1.Focus();
        }
        private void ExecuteDML()
        {
            dr.Close();
            cmd.CommandText = Sqlstr;
            if (cmd.ExecuteNonQuery() > 0)
                MessageBox.Show("Insert or Update operation was successful");
            else
                MessageBox.Show("Insert or Update operation failed");

                LoadData();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Insert into [Stident$] values({0},'{1}' {2},{3})", textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Sqlstr = String.Format("Update [Stident$] Set Sname='{0},Class={1}, Fees= {2} where Sno={3}", textBox2.Text, textBox2.Text, textBox3.Text, textBox4.Text);
            dr.Close();
            ExecuteDML();
        }
    }
}

Thursday, 25 April 2013

DataList, Repeater and FormView and Details View Controls

Today, I practiced some examples using Data List Control, Repeater and FormView Controls in Asp.Net.
 
DataList Control: 

Datalist control is similar to gridview except that it has no predefined layout and hence it can be designed in any layput you want, which is not possible with gridview because it has predefined table layout. It doesn't support paging and sorting wheareas gridview supports paging and sorting.

Repeater:

Repeater control can display multiple rows to gridiew and datalist. But unlike gridview and datalist the data in repeater is readonly.Similar to datalist it has no predefined layout and you can design it with any layout. As repeater is readonly, it has very limited set of properties, methods and events and hence it is very light weight and provides fast access, it has the important properties DatasourceId and Datasource. It has only one important event ItemCommand that will be raised when user click on any button within the repeater.