Vous êtes sur la page 1sur 30

SAMPLE PAPER 2 Q.1 )Attempt any four of the following: a)What are Assemblies & Namespaces describe them.

Ans. Assemblies: Assemblies are the building blocks of the .Net framework, they form the fundamental unit of deployment , version control, reuse, security permissions and more. The purpose of an assembly is to specify a logical unit or building block, applications that encapsulate certain properties. Basically, the term assembly refers to both a logical construct and a set of physical files. A .Net application consist of one or more assemblies. Logically Speaking, an assembly is just a set of specifications as follows:
1. An Assembly specifies the MSIL code that is associated with the assembly. This code lies in portable executable files. 2. An assembly specifies security permissions for itself. 3. An assembly specifies a list of data types and provides scoping for those types. The scoping provided by an assembly means that different types may have the same name, as long as they belong to different assemblies and can therefore be distinguished by means of the assembly to which they belong. 4. An assembly specifies the rules for resolving external types and external references, including references to other assemblies. 5. An assembly specifies which of its parts are exposed outside the assembly and which are private to the assembly itself. Namespaces: The notion of the namespace plays a fundamental role in the .Net framework. In general, a namespace is a logical grouping of types for the purpose of identification. We cannot build a VB.Net application without using the classes from the .net system namespace. The .Net framework class Library(FCL), consist of several thousand classes and other types ( such as interfaces, structures and enumerations that are divided into over 90 namespaces.) Thus, a namespace is a collection of different classes. All VB applications are developed using the classes from the >net system namespace. The namespace with all the functionality is the system namespace. All other namespaces are based on the namespaces. Some of the namespaces are: System System.Collections System.configuration System.ComponentModel System.Io System.Text System.Text.RegularExpressions System.Web.Services System.XML

Compiled By Prof. Vaibhav Vasani

b)Describe the keywords: overridable, overrides, Non-overridable, & must override with example. Ans. overridable, overrides, Non-overridable, & must override are the modifiers that are to control how properties and methods are overridden. Overridable: Allows the property or method in a class to be overridden in a derived class. Overrides: Overrides an overridable property or method defined in the base class. NotOverridable: prevents a property or method from being overridden in an inheriting class. Public methods are NotOverridable by default. MustOverride : requires that derived class override the property or method. When the MustOverride keyword is used, the method definition consists of just the subFunction or property statement. No other statements are allowed and specifically there is no End Sub statement. MustOverride methods must be declared in MustInherit classes. Example:
Imports system Module module1 Sub main() Dim o As New c2() o.show() Console.Read() End Sub End Module Class c1 Overridable Sub show() Console.WriteLine("show old method") End Sub End Class Class c2 Inherits c1 Public Overrides Sub show() Console.WriteLine("show new and improved method") End Sub End Class

c)Describe 4 date & time related functions used in VB.Net with example. d)With example explain any 8 Meta characters used in VB.Net. Ans. Meta characters are the characters that have special meaning within the language of regular expressions. These include the following: Characters Description . The dot matches any single character. \n Matches a newline character ( or CR+ LF combination) \t Matches a tab (ASCII 9) \d Matches a digit (0-9) \D Matches a non-digit. Compiled By Prof. Vaibhav Vasani

\w \W \s \S \ ^ $ ()
Examples: pattern . .* ^c:\\

Matches an alphanumeric character. Matches a non-alphanumeric character. Matches a whitespace character. Matches a non-whitespace character. Use \ to escape special characters. For example, \. Matches a dot and \\ matches backslash. Match at the beginning of the input string. Match at the end of the input string. Match a group pattern.

Inputs(matches) a, b , c, 1, 2, 3 Abc, 123, any string, even no characters would match C:\windows C:\\\\\ C:\foo.txt C:\followed by anything else


abc 123abc Any string ending with abc


abcabc abcabcabc


123 1z3 133


13 123 1zdfkj3

\d\d \w+@\w+

01, 02, 99, .. email@company.com a@a

Compiled By Prof. Vaibhav Vasani

e)Describe select case statement with example used in VB.Net. Ans. The select case statement executes one of several groups of statements depending on the value of an expression. If your code has the capability to handle different values of a particular variable then you can use a select case statement . you use select case to test an expression, determine which of the given cases it matches and execute the code in that matched case. Syntax: Select testexpression Case expressionlist Statements Case else Else statements End select If testexpression matches any case expressionlist clause, the statements following that case statement run up to the next case, case else or end select statement. Control then passes to the statement following end select. Example:
Module Module1 Sub Main() Dim s As String Dim n As Integer Console.WriteLine("select base language: 1= c++ 2=Java 3=vb.net") Console.Write("please enter your selection") s = Console.ReadLine() n = Integer.Parse(s) Select Case n Case 1 Console.WriteLine("Not bad, try again") Case 2 Console.WriteLine("Not even close") Case 3 Console.WriteLine("you are right, congratulations") Case Else Console.WriteLine("invalid selection") End Select Console.Read() End Sub End Module

f)List & describe 4 advantages of DOTNET framework. Ans. The .Net framework offers a number of advantages to developers. They are given below: 1.Consistent programming model: With .Net, for example, accessing the data with a VB.NET and c#.NET looks very similar apart from slight syntactical differences. Both the programs needto Compiled By Prof. Vaibhav Vasani

import the System.Data namespace, both the programs establish a connection with the database and both the programs run a query and display the data on a dadagrid. This is achieve by using the .NET class library, a key component of the .NET framework. The functionality that the .Net class library provides is available to all .NET languages resulting in a consistent object model regardless of the programming language the developer uses. 2.Direct support for security: When an application accesses dada on a remote machine or has to perform a privileged task on behalf of a nonprivilaged user, security issue becomes important as the application is accessing the data from a remote machine. With .Net, t5he framework enables the developer and the system administrator to specify method level security. It uses industry-standard protocols such as TCP/Ip, XML, SOAP and HTTP to facilitate distributed application communications. This makes distributed computiong more secure because .Net developers cooperate with network security devices instead of working around their security limitations. 3.Simplified Development efforts: In web applications, a developer with classic ASP needs to present data from a database in a webpage. He/She has to write the application logic, (code) and presentation logic, (design) in the same file. ASP.NET and .Net framework simplify development by separating the application logic and presentation logic making it easier to maintain the code. The design code, (presentation logic) and the actual code(application logic) is written separately eliminating the need to mix HTML code with ASP code. ASP.NET can also handle the details of maintaining the state of the controls, such as contents in a textbox, between calls to the same ASP.NET page. The .Net framework simplifies the debugging with support for runtime diagnostics. Runtime diagnostics helps you to track down bugs and also helps you to determine how well n application performs.
4.Cross language compatibility: Cross language compatibility means .Net components can interact with each other irrespective of the languages they are written in. Application written in VB.Net can reference a DLL file written in C# or a C# application can refer to a resource written in VC++, etc. The language interoperability extends to object-oriented inheritance.

Q.2 Attempt any three of the following: [SUNIL.WADHWANI ] a)What is interface? How it is different from class.Write code to demonstrate use of interface. Ans: An interface is definition of methods and property.If a class agrees to implement an interface it must implement all of the properties and methods defined . An interface is declared using the interface keyword. An interface is the type with members that are all public.MustOverride is the default. Compiled By Prof. Vaibhav Vasani

An interface is implemented by the class .A class implementing the interface must provide body for all the members of an interface. To implement an interface , a class uses the Implements keyword to show that it is implementing a particular interface. An interface itself can inherit other interfaces. Difference between Class and Interface. 1. An interface defines how a class may be implemented. An interface is not a class and classes can only implement interfaces. When a class defines a function declared in an interface, the function is implemented, not overridden. Therefore, name lookup does not include interface members. 2. In Interface there is no code and only the templates for the properties and methods. 3. A class can implement more than one interface contrary to class inheirtance where you can only inherit one class. 4. An interface like abstract classes ,can not be instantiated where as classes can be instantiated. Code to Demonstrate use of Interface: Interface sample Sub read() Sub write() Property status() As Integer End Interface Public Class Document Implements sample Private mystatus As Integer = 0 Public Sub New() Console.WriteLine("Creating document") End Sub Public Sub read() Implements sample.read Console.WriteLine("Implementing the Read method.") End Sub Public Property status() As Integer Implements sample.status Get Return mystatus End Get Set(ByVal value As Integer) mystatus = value End Set End Property Public Sub write() Implements sample.write Console.WriteLine("Implementing the Write Method.") End Sub Compiled By Prof. Vaibhav Vasani

End Class Module Module1 Sub Main() Dim doc As New Document doc.status = 1 doc.read() doc.write() Console.WriteLine("Document Status:" & doc.status) Console.ReadLine() End Sub End Module OUTPUT: Creating document Implementing the Read method Implementing the Write Method Document Status:1 b)Describe SQL data provider & OLEDB data provider & state function of classes available in those. Ans: SQL DataProvider: The SQL Server .NET data provider ships with the .NET Framework. It uses the Tabular Data Stream (TDS) protocol to send requests to and receive responses from the SQL Server. This provider delivers very high performance because TDS is a fast protocol that can access Microsoft SQL Server directly without an OLE DB or ODBC layer and without COM interop. The SQL Server .NET data provider can be used with Microsoft SQL Server 7.0 or later. To access earlier versions of Microsoft SQL Server, the OLE DB .NET data provider with the SQL Server OLE DB provider (SQLOLEDB) should be used. The SQL Server .NET data provider classes are located in the System.Data.SqlClient namespace. When working with SQL Server the classes with which we work are described below are: The SqlConnection class: The sql connection class represents a connection to SQL Server data source .We use OleDB connection object when working with databases other than SQL Server. Performance is the major difference when working with SqlConnections and OleDbConnections .SQL connections are said to be 70% faster than Oledb connections. Compiled By Prof. Vaibhav Vasani

The Sqlcommand class: The Sqlcommand class represents a SQL statement or stored procedure for use in a database with SQL Server. The SqldataAdapter: The SqlDataAdapter class represents a bridge between the dataset and the SQL Server Database.It includes the Select, Insert, Delete, and update commands for loading and updating the data. The SqlDataReader: The sqlDataReader class creates a data reader to be used with SQL Server. OLEDB DataProvider: The OLE DB .NET data provider ships with the .NET Framework. It communicates with a data source using a data source-specific OLE DB provider through COM interop. The OLE DB provider, in turn, communicates directly with the data source using native OLE DB calls. The OLE DB .NET data provider supports OLE DB interfaces later than Version 2.5. As a result, some OLE DB providers, including those for Microsoft Exchange Server and Internet Publishing, aren't supported. Also, the OLE DB .NET data provider can't be used with the OLE DB provider for ODBC (MSDASQL). The OLE DB.NET data provider classes are located in the System.Data.OleDb namespace. When working with OLE DB the classes with which we work are described below are: OleDbconnection class : The OleDbconnection class represents a connection to OleDb data source.Oledb connections are used to connect to most databases. OleDbCommand class: The OleDbCommand represents a SQL Statement or the stored procedure that is executed in a database by an OLEDB provider. OleDbDataAdapter class: The OleDbDataAdapter class acts as a middleman between the datasets and OleDb data source.We use the Select ,Insert, Delete,Update commands for loading and updating the data. OleDbReader class: Compiled By Prof. Vaibhav Vasani

OleDbDataReader class creates a data reader for use with an oledb data provider.It is used to read a row of data from the database. The data is read as forward only stream which means that data is read sequentially,one row after another not allowing you to choose a row you want or going backwords.

c) What is home directory ,default document,virtual directory related to ASP.NET Ans: Home Directory: IIS is way to share the files over the internet.Just like as sharing files in Windows over a Windows network,in IIS you need to choose a folder whose files are shared by default,this folder is C:\Inetpub \WWWroot\. In Internet Information Service dialog box,the files that are listed in the right pane are the files created in the :\Inetpub\WWWroot\directory during the installation of IIS.These are Simply a few HTML documents and related images that act as an introduction to IIS To access a particular file in the home directory in IE, the filename must be included in the url after the initial http://LocalHost.

DEFAULT Document: If you visit http://www.microsoft.com/net,you do not get a list of files either you are also sent an HTML page .In fact ,its very rare that an HTTP server will return a list of files to a user or client on the Internet,because It is very user-unfriendly to except a user to select the file that he or she would like to view when he or she visits a site. Second, from a security perspective. To counter these issues ,IIS includes Supprot for a defult document.This is basically the file that IIS will return by default if the user request does not specify specific file to be returned . For example, if the default document is set to be index.htm and the user submits a request for http://localhost, the browser will in fact return http://localhost/index.htm if It exists. IIS will attempt to return the first file in the list and if that does not exist,then the second file and so on. Virual Directories: A virtual directory represents a web application and it points to a physical folder in your computer.

Compiled By Prof. Vaibhav Vasani

A web application is accessed using a virtual directory name instead of a physical folder name. For example, if you have a web application called "Shopcart" in your machine, you will have a virtual directory for this web application. You will access your web application using the URL httP://localhost/Shopcart. If your virtaul directory name is "Test", then your web application url will be "http://localhost/Test". Assume you have a web application called "Shopcart", created under the physical folder "C:\MyProjects\Shopcart". You can go to IIS and see this virtual directory listed. Right click on this virtual directory name in IIS and see the properties. You can see that this virtual directory is pointing to the physical location "C:\MyProjects\Shopcart". If you have a file called "File1.aspx" under the folder "C:\MyProjects\Shopcart\", then you can access this file using Internet Explorer with the URL "http://localhost/Shopcart/File1.aspx"

d)Describe constructor ,parametrized constructor ,shared member & destructor with example. Ans: 1) Constructors are Special kind of sub procedures.A constructor has the following properties: 1. It always has the New. 2. Being a sub procedure , it does not return any value. 3. It is automatically called when a new instance or object of a class is created, hence called a constructor. Example: Imports System Class student Private n As String Public Sub New() n = "unknown" Console.WriteLine("Constructor called...") End Sub Public Property name() As String Get Return n End Get Set(ByVal value As String) n = value End Set End Property End Class Module Module1 Sub Main() Compiled By Prof. Vaibhav Vasani

Dim s As New student Console.WriteLine("Name of Student:" & s.name) s.name = "abc" Console.WriteLine("Name of student:" & s.name) Console.ReadLine() End Sub End Module 2)Parametrized Constructor: Parametrized constructrors allows you to create new instance of a class while simultaneously passing arguments to the new instance. Example: Class student Dim name As String Dim roll As Integer Public Sub New(ByVal n As String, ByVal r As Integer) name = n roll = r End Sub Sub display() Console.WriteLine("Name:" & name) Console.WriteLine("Roll:" & roll) End Sub End Class Module Module1 Sub Main() Dim s As New student("abc", 123) s.display() Console.ReadLine() End Sub End Module 3)Shared Members of the class: In visual Basic .Net ,we can use the shared data members to allow multiple instances of class to refer to a single class level variable. Use the following syntax to declare shared data members : AccessLevel Shared DataMember as DataType Shared members are directly linked to the class and you can declare them as public or private.If you declare data members as public ,they are accessible to any code that can access the class. If you declare the data members as private ,you provide public shared properties to access the private shared property. The following example shows how to create savings account class that uses a public shared data member to maintain interest rates for a savings account. Compiled By Prof. Vaibhav Vasani

Example: Class SavingsAccount Public Shared InteresrRate As Double Public Function CalculateInterest() As Double . End Function End Class The value of InterestRate data member of the SavingsAccount class can be set globally regardless of how many instances of the class are in the use.This value is then used to calculate the interest on the current balance. 4)Destructor Each class in VB.NET is automatically inherited from the object class which contains the method finalize(). This method is guaranteed to be called when your object is garbage collected. You can use it to clean up open resources, such as database connections or to release other resources .You can override this method and put here the code for freeing resources that you reserved when using the object. Class Test Protected Overrides Sub Finalize() Console.WriteLine(Destructing object.) End Sub End Class Module Module1 Sub Main() Dim t As New Test() Console.ReadLine() End Sub End Module The Finalize() sub procedure is called automatically when the object is about to be destructed.(when garbage collector is about to destroy your object to cleanup the memory).In c++ programmers had to manage the memory allocation and de-allocation explicitly.Destructors were used there to free the memory allocated by the object.But with VB.NET, the memory is managed autoamatically on behalf of your program. Q. 3 Attempt any three of the following:[ Chaitanya ] a) Describe System.web.mail namespace & System.Net.mail namespace & their purpose. Ans) System.Web.Mail : Compiled By Prof. Vaibhav Vasani

1. The System.Web.Mail namespace contains classes that enable you to construct and send messages 2. System.Web.Mail is not a full .NET native implementation of the SMTP protocol. Instead, it uses the existing CDONTS and CDOSSYS dlls already written by Microsoft for ASP. 3. When the SmtpMail class sends the MailMesage, the SmtMail class checks the OS version. If the version is <= 4, the CDONTS.Newmail object is used. For all OSs greater than 4, the CDO.Message object is used. 4. System.Web.Mail can only send email. We cannot read e-mails using this namespace. 5. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. This namespace includes three classes : 1. MailAttachment : Provides properties and methods for constructing an e-mail attachment. 2. MailMessage : Provides properties and methods for constructing an email message. 3. SmtpMail : Provides properties and methods for sending messages using the Collaboration Data Objects for Windows 2000 (CDOSYS) message component. System.Net.Mail : 1. The System.Net.Mail namespace contains classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery if you are using the 2.0 (or higher) .NET Framework. 2. Unlike System.Web.Mail, which was introduced in the 1.0 Framework, it is not built upon the CDO/CDOSYS libraries. Instead it is written from the ground up without any interop. 3. System.Net.Mail can only send email. We cannot read e-mails using this namespace. 4. Although some functionality has been removed, the new System.Net.Mail namespace is much more versatile than the older CDO dependant System.Web.Mail. This namespace includes following classes: 1. MailAddress : Represents the address of an electronic mail sender or recipient. 2. MailMessage : Represents an e-mail message that can be sent using the Smtp Client class. 3. Attachment : Represents an attachment to an e-mail. 4. SMTPClient : Allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). b) Write Code to display content of emp.mdb file using command object & datareader object. Ans) Compiled By Prof. Vaibhav Vasani

Imports System.Data.oledb Module Module1 Sub Main() Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\USER\My Documents\Emp.mdb") Dim com As New OleDbCommand("Select * from Employee", con) con.Open() Dim dr As OleDbDataReader = com.ExecuteReader Console.WriteLine("Emp_Id" & Microsoft.VisualBasic.Constants.vbTab & "Emp_name") While (dr.Read) Console.WriteLine(dr(0) & Microsoft.VisualBasic.Constants.vbTab & dr(1)) End While con.Close() Console.ReadLine() End Sub End Module Output: Emp_Id Emp_name 1 ABC 2 PQR 3 XYZ c) Describe BrowserType component of ASP.Net. Ans) 1. BrowserType component is used in ASP but it still works on ASP.Net(aspcompat=true). 2. BrowserType object determines the type, capabilities and version number of a visitor's browser. It is created as follows: Syntax <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> 3. When a browser connects to a server, a User Agent header is also sent to the server. This header contains information about the browser. 4. The BrowserType object compares the information in the header with information in a file on the server called "Browscap.ini". 5. If there is a match between the browser type and version number in the header and the information in the "Browsercap.ini" file, the BrowserType object can be used to list the properties of the matching browser. If there is no match for the browser type and version number in the Browscap.ini file, it will set every property to "UNKNOWN". Example : Compiled By Prof. Vaibhav Vasani

<html> <body> <% Set MyBrow=Server.CreateObject("MSWC.BrowserType") %> <table border="0" width="100%"> <tr> <th>Client OS</th><th><%=MyBrow.platform%></th> </tr><tr> <td >Web Browser</td><td ><%=MyBrow.browser%></td> </tr><tr> <td>Browser version</td><td><%=MyBrow.version%></td> </tr><tr> <td>Frame support?</td><td><%=MyBrow.frames%></td> </tr><tr> <td>Table support?</td><td><%=MyBrow.tables%></td> </tr><tr> <td>Sound support?</td><td><%=MyBrow.backgroundsounds%></td> </tr><tr> <td>Cookies support?</td><td><%=MyBrow.cookies%></td> </tr><tr> <td>VBScript support?</td><td><%=MyBrow.vbscript%></td> </tr><tr> <td>JavaScript support?</td><td><%=MyBrow.javascript%></td> </tr> </table> </body> </html> Output: Client OS Web Browser Browser version Frame support? Table support? Sound support? Cookies support? VBScript support? JavaScript support? IE 5.0 True True True True True True WinNT

d) Describe DataView with example. List methods of DataView. Ans) o We can use DataView to get a snapshot of the data in a table. DataViews are much like read only mini-datasets in which you can load only a subset of a dataset. o DataView provide three key features : Compiled By Prof. Vaibhav Vasani

Sorting based on any column criteria Filtering based on any combination of column values Filtering based on the row state (such as deleted, inserted, and unchanged)

o When creating a DataView object, you specify the underlying DataTable in the constructor: // Create a new DataView for the Customers table. DataView view = new DataView(ds.Tables["Customers"]); o Every DataTable also provides a default DataView through the DataTable.DefaultView property: // Obtain a reference to the default DataView for the Customers table. DataView view = ds.Tables["Customers"].DefaultView; o After creating DataView object, it can be bound to DataGridView control for displaying the contents of view. Following Application demonstrates the use of DataView: Imports System.Data.oledb Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\itcl4.ITSERVER\My Documents\Student1.mdb") Dim adap As New OleDbDataAdapter("select * from StudInfo", con) Dim ds As New DataSet() Dim dv As DataView adap.Fill(ds, "StudInfo") dv = New DataView(ds.Tables("StudInfo")) DataGridView1.DataSource = dv End Sub End Class OUTPUT :

Compiled By Prof. Vaibhav Vasani

Methods Of DataView Class: o AddNew Inserts a new row into the underlying DataTable and returns a DataRowView object that represents the new row. o Delete - Removes a row at the specified index. This affects both the DataView and the underlying DataTable. o Find - Returns the index of a single matching row, using the current DataView sort order. o FindRows - Returns an array with every DataRowView object that matches a specified search expression in a given DataView. Q4) Attempt any four of the following: [ Gulshan ] a)List and Describe different file extension used in VB.Net. Ans. When you save a solution its given the file extension .sln and all the projected in the solution are saved with the extension .vbproj. Heres a list of the types of the extensions you will see in the files in the VB.Net. These are as follows: .vb: Can be a basic window form, a code file, a module file for storing functions, a user control, a data form, a custom control, an inherited form, a web custom control, an inherited user control, a windows service, a custom setup file, an image file for creating a custom icon or an assembly info file. .xsd: An XML schema provided to create type datasets. .xml: An XML document file. .htm: An HTML document. .txt: A text file. .xslt: An XSLT style-sheet file, used to transform XML documents and XML Schemas. .css: A cascading style-sheet file. .rpt: A crystal report. .bmp: A bitmap file. .js: A Jscript file. .vbp: A VBScript file. .wsf: A window scripting file. .aspx: A web form. .asp: An active server page. .web: A web configuration file. .asax: A global application class, used to handle global ASP.NET application level events. .resx: A resource file used to store resource information. .config: Application configuration files contain settings specific to an application. b)Write a code to insert data in book.mdb table using AddWithValue collection of command object. Ans. Compiled By Prof. Vaibhav Vasani

Imports System.Data.OleDb Imports System.Data Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conobj As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Gulshan\Documents\Book.mdb") Dim com As New OleDbCommand("insert into Stud Values(@srno,@name,@price)", conobj) com.Parameters.AddWithValue("@srno", TextBox1.Text) com.Parameters.AddWithValue("@name", TextBox2.Text) com.Parameters.AddWithValue("@price", TextBox3.Text) conobj.Open() com.ExecuteNonQuery() conobj.Close() End Sub Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Clear() TextBox2.Clear() TextBox3.Clear() End Sub End Class c)Describe 2 methods & properties of session object. Ans. Properties: i) Session.TimeOut Property: The Session.TimeOut Property can be used to set the expiration time in minutes for the session. If the user does not refresh the page or request another page within the allotted time, the session is automatically terminated and the resources are released. The default is 20 minutes. This property is mostly used in many online banking systems, to avoid misusages. Eg. Response.Write(Default Timeout is: & Session.Timeout) ii) Session.CodePage Property: The Session.CodePage Property can be used to specify how strings are encode on a page. A codepage is simply a set of characters. The default value of the CodePage varies by location and language. For example, the language Hindi or Gujarati uses another characters than English or German. The Session.CodePage property affects the complete all responses in a page. Setting response.codepage explicitly affects a single page while session.codepage affects all responses in session. Eg. Response.Write(Current code page is: & Session.CodePage)

Compiled By Prof. Vaibhav Vasani

Methods: i) Session.Contents.RemoveAll(): The Session.Contents.RemoveAll() or Session.RemoveAll() used to remove all items from a session object. It does not take any parameters or return anything. Eg. Session(Rollno)=1 Session(Name)=ABC Session.Contents.RemoveAll() ii)Session.Contents.Remove(name| index): The Session.Contents.Remove() method or Session.Remove() can be used to remove specific items from a session object. You can either pass the name of the item or the index of the item. When an integer is passed as a parameter then all other items in the list will be automatically updated and it is recommended to pass always the name as a parameter. Eg. Session.Contents.Remove(Rollno) d)Describe the purpose of Repeater control with example. Ans. The Repeater control displays data items in a repeating list. Similar to DataList, the content and layout of list items in Repeater is defined using templates. At a minimum, every Repeater must define an ItemTemplate; Unlike DataList, Repeater has no built-in layout or styles. You must explicitly declare all HTML layout, formatting and style tags within the templates of the control. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Q5.aspx.vb" Inherits="Q5" %> <!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>Untitled Page</title> </head> <script runat=server> Sub Page_Load(ByVal Sender As Object, ByVal e As EventArgs)Handles Me.Load Dim conobj As New SqlConnection(Server=localhost;UID=sa;PWD=sa;database=Northwind) Dim com As New SqlCommand(Select * from Employee,conobj) Dim dr As SqlDataReader conobj.open() dr=com.ExecuteReader() rptEmployees.DataSource=dr rptEmployees.DataBind() dr.Close() conobj.close() End Sub </script> Compiled By Prof. Vaibhav Vasani

<body> <form id=Form1 runat=server> <asp:Repeater ID=rptEmployees Runat=server> <ItemTemplate><%#Container.DataItem(Employee_name)%></ItemTempl ate> </asp:Repeater> </form> </body> </html> e) Write ASP.NET Code to display context of student talbe assume tale is created in SQL dbms system. Ans. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="System.Data" %> <!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>Untitled Page</title> </head> <body> <script runat="server"> Public Sub ButtonClicked(ByVal sender As Object, ByVal e As EventArgs) Dim conobj As New SqlConnection("Server=localhost;UID=sa;PWD=sa;database=Student") Dim ds As New DataSet() Dim adap As New SqlDataAdapter("Select * from Student", conobj) Dim dv As DataView adap.Fill(ds, "Student") dv = New DataView(ds.Tables("Student")) DataGrid1.DataSource = dv End Sub

</script> <asp:DataGrid ID="DataGrid1" runat="server" style="left: 34px; position: absolute; top: 97px" Height="234px" Width="530px"></asp:DataGrid> <form id="form1" runat="server"> <div> <asp:Button ID="Button1" runat="server" Style="left: 228px; position: absolute; top: 45px" Text="Show Data" OnClick="ButtonClicked"/> Compiled By Prof. Vaibhav Vasani

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

Q5. Attempt any four: [ Rohit ] A) List and describe form view,gridview ,detail view& state difference between them. Ans: Form View Control: It is a data bound user interface control that renders as single record at a time from its associated data source,optionally providing paging buttons to navigate between records. Binding to data source controls,such as SqlDataSource and ObjectDataSource. The features of Form View control are as follows: Built in inserting,updating and deleting capabilities. Built in paging capabilities Customizable appearance through user defined templates ,themes and styles. Grid View: The Grid view control displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record. The features of grid view control are as follows: Binding to data source controls,such as SqlDataSource Built in sorting,updating,deleting,paging capabilities Built in row selection capabilities Multiple key fields Multiple data fields for the hyperlink columns Customizable appearance through themes and styles

Detail View: It is a data bound usr interface control that renders a single record at a time from its associated data source,optionally providing paging buttons to navigate between records. It is similar to the form view of a Access database and is typically used for updating and /or inserting new records.

Difference; 1. The difference between the form view and the detail view is that the DetailsView control uses a table-based layout where each field of the data Compiled By Prof. Vaibhav Vasani

record is displayed as a row in the control. In contrast, the FormView control does not specify a pre-defined layout for displaying a record.

2. FormView is a data-bound user interface control that renders a single record at a time from its associated data source, optionally providing paging buttons to navigate between records. It is similar to the DetailsView control, except that it requires the user to define the rendering of each item using templates, instead of using data control fields. The main difference between DetailsView and FormView is that DetailsView has a built-in tabular rendering, whereas FormView requires a userdefined template for its rendering. The FormView and DetailsView object model are very similar otherwise.

b)Write code to create data table in asp.net. Ans: //Default.aspx.vb Imports System.Data.OleDb Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Dim table As New DataTable Dim column As DataColumn Dim row As DataRow Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load column = New DataColumn column.DataType = System.Type.GetType("System.Int32") column.ColumnName = "id" table.Columns.Add(column) column = New DataColumn column.DataType = System.Type.GetType("System.String") column.ColumnName = "item" table.Columns.Add(column) Dim i As Integer For i = 0 To 10 row = table.NewRow row("id") = i row("item") = "item" & i table.Rows.Add(row) Next GridView1.DataSource = table GridView1.DataBind() Compiled By Prof. Vaibhav Vasani

End Sub End Class //Default.aspx <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Qb</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </div> </form> </body> </html>

c)Describe inheritance modifiers like Inherits,Not Inheritable,Must inherit with example. Ans: Visual basic introduces the following class level statements and modifiers to support inheritance: Inherits Statement:specifies the base class NotInheritable modifier:prevents programmers from using the class as a base class MustInherit modifier:specifies that the class is intended for use as a base class only.instances of MustInherit classes cannot be created directly;they ca only be created as base class instances of a derived class.

Inherits we use the Inherits keyword to define a derived class that will inherit from an existing base class. Example of Inherits Keyword: Compiled By Prof. Vaibhav Vasani

Public class CheckingAccount Inherits BankAccount Private sub ProcessCheck() Add code to process a check drawn on this account End sub End class NotInheritable NotInheritable keyword define a class that cannot be used as a base class for inheritance.A compiler error is generated if another class attempts to inherit from this class. Example: Public NotInheritable class TestClass . End class Public class Derivedclass The following line generates a compiler error Inherits TestClass .. End class MustInherit MustInherit keyword define classes that are not intended to be used directly as instantiated objects. The resulting class must be inherited as a base class for use in an instantiated derived class object. Example: Public MustInherit class BaseClass .. End class If the client code attempts to create an instance of this type of class a compiler error is generated. Compiled By Prof. Vaibhav Vasani

d)What are server variables? write code to display all server variables with their values on IE. Ans: Server Variables: Server variables are the predefined environmental variables which give the additional information related to the application. Some examples of server variables are: REMOTE_ADDR, REMOTE_HOST, SERVER_PORT, SERVER_PROTOCOL, SERVER_SOFTWARE Request.serverVariables property: The request.ServerVariables property can be used to retrieve information about the predefined server variables. //program <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Experiment 9</title> </head> <% Dim servervar For Each servervar In Request.ServerVariables Response.Write("" & servervar & ":" & Request.ServerVariables(servervar) & "<br/>") Next %> <body> <form id="form1" runat="server"> Compiled By Prof. Vaibhav Vasani

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

e)Describe Get and Post method? State difference between them. Ans: GET is simply the method in which the browser compiles a URL.A typical URL in this context will consist of a protocol, for example, HTTP for hypertext or FTP for file transfer, a fully qualified domain name, such as www.aspalliance.com, followed by a path, such as /chrisg/, and then the page to GET, such as default.asp or index.html.You can add information as parameters, called a querystring. When a browser sends information using the POST method, the parameters are compiled in the same way but sent separately in the HTTP header, and so are not seen in the URL portion of the browser like GET requests are. Forms often use POST for this very reason. Get-> we can transfer limited data and its not secure. post-> we can transfer unlimited data. ans its a secure.

Q:6) Attempt any four: [ Janu ] A) Describe structure of ASP.Net page Ans. Structure of ASP.Net page: ASP.Net page consists of the following page elements 1. Directives. 2. Code Declaration Block 3. Code Render block 4. ASP.Net Controls 5. Server side comments 6. Server side include directives. Directives :Directives control the compilation of an ASP.Net page. The beginning of a directive is marked with the characters <%@ Page Language = VB%> character. This is shown in line 1 of the example above. A directive can appear anywhere in Compiled By Prof. Vaibhav Vasani

the page but by convention, a directive appears typically at the top of an ASP.Net page. There are two types of directives: a) Page Directives : This directive appears on the top of an ASP.Net page. It specifies which programming language is being used to write an ASP.Net page. For example, if we Want to use VB as our page language, we will use the following directive: <%@Page Language = VB%> b) Import Directives : By default, only certain namespaces are automatically imported into an ASP.Net page. If you want to refer to a class that is not a member of one of the default namespaces, then you must explicitly import the namespace of the class or you must use the fully qualified name of the class.
%@Import Namespace = System.Web.Mail%

This line imports all of the classes of the System.Web.Mail namespace, to send the mail through the SmtpMail class. Code Declaration Block :It contains all the application logic for your ASP.Net page & all the global variable declarations, subroutines & functions. It must appear within a <Script Runat = server> tag. Code Render Block :If you need to execute code within the HTML or text content of your ASP.Net page, you can do so within the code render blocks. The two types of Code Render Blocks are: i) Inline code: It executes a statement or series of statements. This type of code begins with the characters <% & ends with the characters %> ii) Inline Expressions: It begins with the characters <%= and ends with the characters =%> Code Render Block contains additional instructions that ASP.Net pages uses to produce output. ASP.Net Controls :ASP.Net controls can be freely interspersed with the text of HTML content of a page. The only requirement is that the control should appear within the <form Runat = Server> tag. One significant limitation of ASP.Net page is that it contains only one <form Runat = Server> tag. This means you cant group ASP.Net into multiple forms on a page. And if you try this you will get an error. Server Side Comments :Compiled By Prof. Vaibhav Vasani

To add comments to your ASP.Net pages one can use server side comments blocks. The beginning of the comment is marked with the characters <%-- and end is like --%> . It can be added to the ASP.Net pages for the purpose of documentation. Server Side Include Directives :You can include a file in an ASP.Net page by using one of the two forms of the server sode include directives. If you want to include a file that is located in the same directory or in a subdirectory of the page including the file, you can use the following directive : <!--#INCLUDE file=default2.aspx -- > OR <!--#INCLUDE virtual=/Directoy/default2.aspx -- > B) Describe & list different web form controls. c) Describe validator control project.List different validator & their purpose with example? Ans: 1)Compare Validator: Compares the value of one i/p control to the value of another i/p control or to a fixed value. If they do not match, the error message that you set will be displayed into this control. Syntax: <asp:CompareValidator id=CompareValidator1 runat="server" ErrorMessage="CompareValidator"> </asp:CustomValidator> 2)Custom/validator Allows you to write a method to handle the validation of value entered. Syntax: id=CustomValidator1 runat="server" ErrorMessage="CustomValidator"> </asp:CustomValidator> 3)Range Validator Checks that the user enteres a value that falls between two values(range).If it is not ,the ErrorMessage that you will set be displayed into the control.. Compiled By Prof. Vaibhav Vasani

Syntax: <asp:RangeValidator id=RV! runat="server" ErrorMessage="RangeValidator"/> 4)RegularExpressionValidator Ensures that value of an input control matches a specified pattern.. Syntax: <asp:RegularExpressionValidator id=RegularExpressionValidator1 runat="server"ErrorMessage="RegularExpressionValidator"/> 5)RequiredFieldValidator Makes an i/p control a required field. Syntax: <asp:ReqiredFieldValidator id=RFV1 runat="server"ErrorMessage="RequiredFieldValidator"/> 6)ValidaionSummary Displays a report of all validation errors occured in a web page. Syntax: <asp:ValidationSummaryID="VSI" DisplayMode="BulletList" HeaderText="someText" EnableClientScript="true" runat="server"/> d) List & describe different Data set method for XML processing. Ans: The DataSet object is stored in memory in a binary format just like any other .NET object. It is always remoted and serialized in a special XML format called the DiffGram. A Dataset is a basket that stores data obtained from data source. This data source can also be XML document. There may be different type of dataset typed or untyped. A typed dataset consists of XML schema. But untyped dataset does not have this type of schema in it. The XML schema contains whole information about the relation structure. It contains information about the relation structure. It contains information regarding table, constraints and relation. The table below presents the Dataset's method you can use to work with XML, both in reading and in writing.

Compiled By Prof. Vaibhav Vasani

Methods: 1.ReadXml 2.WriteXml 3.WriteXmlSchema 4.ReadXmlSchema 5.GetXml 6.GetXmlSchena ReadXML: It is a method used to fill a Dataset with a data from XML.It can read data from a file, a stream or an XmlReader and takes as arguements the source of XMLReadMode argument. Syntax: public XmlReadMode ReadXml(String XmlReadMode);

WriteXML It is a method used to write the XML,representation of the DataSet into a file.a stream an XmlWriter object or a string.The XML representation can include or not ionclude,schema information.The actual behavior of the behavior of the WriteXml method can be controlled through the optional XmlWriteMode parameter. Syntax: public XmlWriteMode WriteXml(String,XmlWriteMode); WriteXmlSchema: It is a method to create a schema of XML file.. ReadXMLSchema: Reads the XML schema into the DataSet.

Compiled By Prof. Vaibhav Vasani