Wednesday, 8 May 2013

LINQ to SQL (Example)

Example : Add a new form in project and design it as following.



Output :




Coding:


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;

namespace LinqProject1
{
   public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        CS11DBDataContext dc;
        List cust;
        int rno = 0;
        private void Form2_Load(object sender, EventArgs e)
        {
            dc = new CS11DBDataContext();
            cust = dc.GetTable().ToList();
            ShowData();
        }
        private void ShowData()
        {
            txtCustID.Text = cust[rno].CustId.ToString();
            txtCname.Text = cust[rno].Cname.ToString();
            txtCity.Text = cust[rno].City.ToString();
            txtBalance.Text = cust[rno].Balance.ToString();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (rno0)
            {
                rno -= 1;
                ShowData();
            }
            else
            {
                MessageBox.Show("First record of the table", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        } 
    } 
}

LINQ to SQL

Microsoft has provided LINQ as a lightweight facade that provides a strongly typed interface to the underlying data stores. LINQ provides the means for developers to stay within the coding environment they are used to and access the underlying data as objects that work with the IDE, intellisense, and even debugging. With LINQ the queries you create now become first-class citizens within the .Net framework alongside everything else you are used to. When you work with queries for the data store you are working with, you will quickly realize that they now work and behave as if they are types in the system.

LINQ to SQL in particular is a means to have a strongly typed interface against a SQL Server database. You will find the approach that LINQ to SQL provides is by far the easiest approach to the querying SQL Server available at the momoent. It is important to remember that LINQ to SQL is not only about querying data, but you also are able to perform Insert/Update/Delete statements that you need to perform which are known as CRUD operations (Create/Read/Update/Delete). Visual Studio comes into strong play with LINQ to SQL in that you will find an extensive user interface that allows you to design the LINQ to SQL classes you will work with.

Example : 

Place a DataGridView control on the first Form of project, change the name of DataGridView as gdView and write the following code:

Output:

 

Coding :
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.Linq;

namespace LinqProject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            CS11DBDataContext dc = new CS11DBDataContext();
            Table tab = dc.GetTable();
            dgview.DataSource = tab;
        }  
      
    }
}

Tuesday, 7 May 2013

Collections

     Arrays are simple data structures used to store data items of a specific type Although commonly used, arrays have limited capabilities. For instance you must specify an array size, and if at execution time you wish to modify it you must do so by creating a new array or by using array classes resize method, which creates a new array and copies the existing elements into the new array.
     Collections are a set of prepackaged data structures that offer greater capability than traditional arrays. They are reusable, reliable, powerful and efficient and have been carefully designed and tested to ensure quality and performance. Collections are similar to arrays but provide additional functionalities, such as dynamic resizing - They automatically increase their size at execution time to accommodate additional elements, inserting of new elements, removing of existing elements etc.
     Initially .net introduces so many collection classes under the namespace System.Collections like Stack, Queue, LinkedList, SortedList, ArrayList etc.

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.