Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
115 views50 pages

4th Sem VB NET 2022

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 50

RJS FIRST GRADE COLLEGE

KORAMANGALA, BENGALURU
Course:BCA403T Subject: VISUAL PROGRAMMING.NET

UNIT-1 INTRODUCTION TO DOT NET FRAMEWORKS

SECTION-A
Two marks questions
1. What is class library with reference to .NET framework?
 The Framework class library (FCL) is a comprehensive collection of reusable
types including classes, interfaces and data types included in the . NET
Framework to provide access to system functionality. The . NET FCL forms the
base on which applications, controls and components are built in . NET.

2. Explain common type system with reference .NET Framework.


 It is meant for declaring different data types, how they are managed in runtime
with cross language integration, type safety with great performance execution.

3. What is CLS in .NET Framework?


 A Common Language Specification (CLS) is a document that says how computer
programs can be turned into Common Intermediate Language (CIL) code. When
several languages usethe same byte code, different parts of a program can be
written in different languages

4. Explain properties window.


 The Properties window is used to display properties for objects selected in the
two main types of windows available in the Visual Studio integrated
development environment (IDE). These two types of windows are: Tool
windows such as Solution Explorer, Class View, and Object browser .
5. Explain code window.
 The Code window is where you write any code associated with your VBA
project. You could write code which is executed when the user clicks a button in
anpicture, or it could be a part of a procedure library you've written to serve your
entire project. Two drop-down lists are located just below the title bar.
6. What is common language runtime with reference to .NET framework?

 The Common Language Runtime (CLR), the virtual machine component of


Microsoft . NET Framework, manages the execution of . NET programs.
7. Explain class view window.

 Class View is shown as part of Solution Explorer and as a separate window. Class
View displays the elements of an application. The upper pane displays
namespaces, types, interfaces, enumerations, and classes, and the lower pane
displays the members that belong to the type selected in the upper pane.
8. What is solution explorer?

 Solution Explorer is a special window that enables you to manage solutions,


projects, and files. It provides a complete view of the files in a project, and it
enables you to add or remove files and to organize files into subfolders.
9. what is server explorer?

 Server Explorer allows you to graphically create databases, tables, views, and
stored procedures completely from within Visual Studio . NET. You can also edit
and delete existing database objects.
10. What is task list in .net framework?

 Task List is nothing but an integrated to-do list within the Visual Studio
framework.
11. What is output window?

 The Output window displays status messages for various features in the integrated
development environment (IDE).
12. What is command window in .net framework?

 The Command window is used to execute commands or aliases directly in the


Visual Studio integrated development environment (IDE). You can execute both
menu commands and commands that do not appear on any menu.

SECTION B
Ten marks questions
13. What do you mean by IDE of VB.Net. Explain the various features of .Net.

 An integrated development environment (IDE), also known as integrated design


environment and integrated debugging environment, is a type of computer
software that assists computer programmers to develop software. In the case of
Visual Basic . NET, that IDE is Visual Studio.
Features of .Net are

a. Common language Environment:-


All .NET applications run under a common execution environment, called the
Common Language Runtime. The CLR facilitates the interoperability between
different .NET languages such as C#, Visual Basic, Visual C++, etc. by providing
a common environment for the execution of code written in any of these
languages.

b. Common Type System:-


The .NET framework follows types of systems to maintain data integrity across
the code written in different .NET compliant programming languages. CTS
ensures that objects of the programs that are written in different programming
languages can communicate with each other to share data.The common type
system CTS defines a set of types and rules that are common to all languages
targeted at the CLR.

c. Multi-language support:-
NET provides multi- language support by managing the compilers that are used to
convert the source to intermediate language (IL) and from IL to native code, and
it enforces program safety and security.

d. Tool Support
The CLR works hand-in-hand with tools like visual studio, compilers, debuggers,
and profilers to make the developer's job much simpler.

e. Security
The CLR manages system security through user and code identity coupled with
permission checks. The identity of the code can be known and permission for the
use of resources granted accordingly. This type of security is a major feature of
.NET. The .NET framework also provides support for role-based security using
Windows NT accounts and groups.

f. Automatic Resource Management

The .NET CLR provides efficient and automatic resource management such as
memory, screen space, network connections, database, etc. CLR invokes various
built-in functions of .NET framework to allocate and de-allocate the memory of
.NET objects.

g. Easy and rich debugging support:-

The .NET IDE (integrated development environment) provides an easy and rich
debugging support. Once an exception occurs at run time, the program stops and
the IDE marks the line which contains the error along with the details of that error
and possible solutions.
14. Discuss any four advantages of .Net.

Advantages of .Net are

a. Object-Oriented Programming (OOP):.NET is based on object-oriented


programming (OOP). This is where the software is divided into smaller chunks,
which then allows developers to work on them one at a time. Once the work on one
part is done, they can move on to the next. When all the smaller pieces are complete,
they can then be combined and managed more effectively.

b. Great Caching System: The simplicity of the caching system of .NET makes it
reliable and easy to come temporarily store data. it allows for the cache
implementation to be customized, so developers can improve performance and scale
as needed.

c. Visual Studio: NET comes with the Visual Studio Integrated Development
Environment (IDE). This tool allows developers to create applications without much
difficulty, as well as debug and publish them across multiple platforms and OS.

d. Cross-Platform Development: .NET has become a cross-platform implementation


that can be used to develop applications on multiple OS.It is also open-source,
which means that developers can improve with it as much as they want.

15. Write short notes on CLR explaining role and advantages.

CLR is the basic and Virtual Machine component of the .NET Framework. It is
the run-time environment in the .NET Framework that runs the codes and helps in making the
development process easier by providing the various services.

Role of CLR in the execution of a program

a. Suppose you have written a VB program and save it in a file which is known as the
Source Code.
b. Language specific compiler compiles the source code into the MSIL(Microsoft
Intermediate Language) which is also known as the CIL(Common Intermediate
Language) or IL(Intermediate Language) along with its metadata. Metadata includes all
the types, actual implementation of each function of the program. MSIL is machine-
independent code.
c. Now CLR comes into existence. CLR provides the services and runtime environment to
the MSIL code.CLR includes the JIT(Just-In-Time) compiler which converts the MSIL
code to machine code which further executed by CPU.
Advantages of CLR

 It improves the performance by providing a rich interact between programs at run time.
 Enhance portability by removing the need of recompiling a program on any operating system
that supports it.
 Security also increases as it analyzes the MSIL instructions whether they are safe or unsafe.
 Support automatic memory management with the help of Garbage Collector.

16. a. Write short notes on CTS.


b. what do you mean by managed code and unmanaged code.

Ans a. Common Type System (CTS):


Every programming language has its own data type system, so CTS is
responsible for understanding all the data type systems of .NET programming
languages and converting them into CLR understandable format which will
be a common format.

There are 2 Types of CTS that every .NET programming language have :
1. Value Types:
Value Types will store the value directly into the memory location.
These types work with stack mechanisms only. CLR allows memory
for these at Compile Time.

2. Reference Types:
Reference Types will contain a memory address of value because the
reference types won’t store the variable value directly in memory.
These types work with Heap mechanism. CLR allot memory for these
at Runtime.

b. A. Managed code:
 The MSIL code which is managed by the CLR is known as the Managed
Code.

B. Unmanaged code:
 Before .NET development, programming languages like.COM Components
& Win32 API do not generate the MSIL code. So these are not managed by
CLR rather managed by Operating System.

17. What is VB.NET? Explain any five features and advantages of VB.NET.

 VB.NET stands for Visual Basic.NET, and it is a computer programming


language developed by Microsoft. It was first released in 2002 to replace Visual
Basic 6. VB.NET is an object-oriented programming language. This means that it
supports the features of object-oriented programming which include
encapsulation, polymorphism, abstraction, and inheritance.

Features
 VB.NET is not case sensitive like other languages such as C++ and Java.
 It is an object-oriented programming language. It treats everything as an object.
 Automatic code formatting, XML designer, improved object browser etc.
 Garbage collection is automated.
 Support for Boolean conditions for decision making.

Advantages
 Our code will be formatted automatically.
 We can use object-oriented constructs to create an enterprise-class code.
 we can create web applications with modern features like performance counters, event
logs, and file system.
 we can create our web forms with much ease through the visual forms designer. You
will also enjoy drag and drop capability to replace any elements that you may need.
 We can connect our applications to other applications created in languages that run on
the .NET framework.

18. Explain any five tools in vb.net toolbox.


Toolbox
In Visual Basic.net toolbox consist of Controls, Containers, Menu Options, Crystal
Report Controls, Data Controls, Dialogs, Components, Printing and other controls,
that are used in a form to design the interfaces of an application.

Images Control Name Description

Pointer Used to move and resize controls and forms.

Button This Control triggers an action when accessed.

Check Box Control that has values either true or false

CheckedList Box Lists check box next to each item

A combination of list and text box controls that enables to


Combo Box
select as well as edit text.

DateTimePicker Display a calender picker to choose the day and date.


UNIT-2 VB.NET CREATING APPLICATIONS

SECTION-A

Two marks questions

1. Explain variables in VB.NET.

 A variable is nothing but a name given to a storage area that our programs can
manipulate. Each variable in VB.Net has a specific type, which determines the
size and layout of the variable's memory; the range of values that can be stored
within that memory; and the set of operations that can be applied to the variable .

2. Explain constant in VB.NET.


 The constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.Constants can be of any of
the basic data types like an integer constant, a floating constant, a character
constant, or a string literal.
3 . What is vb.net String?

 In VB.NET, string is a sequential collection of characters that is called a text. The


String keyword is used to create a string variable that stores the text value.
4. What is vb.net data validation?
 Data validation is the process of ensuring, at least as far as is possible, that the
data given to a program by a user or from a file (essentially, the program's input)
is of the correct type, and in the correct format.
5. What is meant by sub procedure?

 A Sub procedure is a separate set of codes that are used in VB.NET programming
to execute a specific task, and it does not return any values. The Sub procedure is
enclosed by the Sub and End Sub statement.
6. what if meant by function inVB.NET?

 In VB.NET, the function is a separate group of codes that are used to perform a
specific task when the defined function is called in a program. After the execution
of a function, control transfer to the main() method for further execution.
7. what is meant by standard modules in VB.NET?
 A module (sometimes called a standard module) is similar to a class but with
some important distinctions. Every module has exactly one instance and does not
need to be created or assigned to a variable. Modules do not support inheritance
or implement interfaces.
8. What is VB.NET exception?

 An exception is a response to an exceptional circumstance that arises while a


program is running, such as an attempt to divide by zero. Exceptions provide a
way to transfer control from one part of a program to another.
9. What are arrays in VB.NET?

 An array stores a fixed-size sequential collection of elements of the same type. An


array is used to store a collection of data, but it is often more useful to think of an
array as a collection of variables of the same type.
10. What is use of ado.net?

 ADO.NET is a data access technology from the Microsoft . NET Framework that
provides communication between relational and non-relational systems through a
common set of components. ADO.NET is a set of computer software components
that programmers can use to access data and data services from a database.
11. What is meant by generic in vb.net.

 A generic type is a single programming element that adapts to perform the same
functionality for a variety of data types. When you define a generic class or
procedure, you do not have to define a separate version for each data type for
which you might want to perform that functionality.
12. what is use of crystal reports in vb.net?

 Crystal Report is a Reporting application that can generate reports from various
Data Sources. We can Create Reports, Print and Print Preview of reports from
Crystal Reports.
SECTION-B
Ten marks questions

13. Explain variables and constants with an example.

 Variable: In VB.NET, a variable is used to hold the value that can be used further
in the programming. A variable is a simple name used to store the value of a
specific data type in computer memory. In VB.NET, each variable has a particular
data type that determines the size, range, and fixed space in computer memory.
With the help of variable, we can perform several operations and manipulate data
values in any programming language.
 The declaration of a variable is simple that requires a variable name and data type
followed by a Dim. A Dim is used in Class, Module, structure, Sub, procedure .

Eg: Dim [Variable_Name] As [Defined Data Type]


Dim a As Integer.

Constants:

 As the name suggests, the name constant refers to a fixed value that cannot be
changed during the execution of a program. It is also known as literals. These
constants can be of any data type, such as Integer, Double, String, Decimal,
Single, character, enum, etc.
 In VB.NET, const is a keyword that is used to declare a variable as constant. The
Const statement can be used with module, structure, procedure, form, and class.
 Syntax:
 Eg: Const constname As datatype = value
 Const num As Integer = 10
14. Explain Strings and Lists in VB.net.
Strings:
 In VB.NET, string is a sequential collection of characters that is called a text. The
String keyword is used to create a string variable that stores the text value. The
name of the string class is System.String that contains the various function of
string.
 Declaration of the String variable
 Eg: 1.Dim str As String
 2.Dim abc As String
There are different ways to create a string object in the String.
 To use a String class constructor.
 By using the property or calling method to return a string.
 Use a string literal to define a string variable.
 Use a String concatenation operator (+).
 By using a formatting function to convert a value or object into the string
Representation of the object.

Lists

 The List class is used to store generic types of collections objects. By using a
generic class on the list, we can store one type of object. The List size can be
dynamically different depending on the need of the application, such as adding,
searching or inserting elements into a list.

Properties of the VB.NET List

Property Description
name

Capacity It is used to obtain or set a number that indicates the number of


elements can be placed in a list.

Count It is used to count the number of elements available in the List.

Item It is used to get or set an item at a specified position of the List.

15. Write short notes on sub procedure and function.


Sub procedure

 A Sub procedure is a separate set of codes that are used in VB.NET programming
to execute a specific task, and it does not return any values. The Sub procedure is
enclosed by the Sub and End Sub statement. The Sub procedure does not return
any value.
 Defining the Sub procedure
Following is the syntax of the Sub procedure:

[Access_Specifier ] Sub Sub_name [ (parameterList) ]


[ Block of Statement to be executed ]
End Sub
o Access_Specifier: It defines the access level of the procedure such as
public, private or friend, Protected, etc. and information about the
overloading, overriding, shadowing to access the method.
o Sub_name: The Sub_name indicates the name of the Sub that should be
unique.
o ParameterList: It defines the list of the parameters to send or retrieve data
from a method.

Function
o In VB.NET, the function is a separate group of codes that are used to
perform a specific task when the defined function is called in a program.
After the execution of a function, control transfer to the main() method for
further execution. It returns a value.
o Defining a Function
o The syntax to define a function is:

[Access_specifier ] Function Function_Name [ (ParameterList) ] As Return_Type


[ Block of Statement ]
Return return_val

End Function

Where,
 Access_Specifier: It defines the access level of the function such as public, private, or
friend, Protected function to access the method.
 Function_Name: The function_name indicate the name of the function that should be
unique.
 ParameterList: It defines the list of the parameters to send or retrieve data from a method.
 Return_Type: It defines the data type of the variable that returns by the function.

16. Explain timers in vb.net.

 The timer control is a looping control used to repeat any task in a given time interval. It is
an important control used in Client-side and Server-side programming, also in Windows
Services. Once the timer is enabled, it generates a tick event handler to perform any
defined task in its time interval property. It starts when the start() method of timer control
is called, and it repeats the defined task continuously until the timer stops

 Timer Control Properties


There are following properties of the VB.NET Timer control.
Properties Description

Name The Name property is used to set the name of the control.

Enabled The Enables property is used to enable or disable the timer control.
By default, it is True.

Interval An Interval property is used to set or obtain the iteration interval in


milliseconds to raise the timer control's elapsed event. According to
the interval, a timer repeats the task.

AutoReset The AutoReset property is used to obtain or set a Boolean value that
determines whether the timer raises the elapsed event only once.

Events Events property are used to get the list of event handler that is
associated with Event Component.

CanRaiseEvents It is used to get a value that represents whether the component can
raise an event.

Events of Timer Control

Events Description

Disposed When control or component is terminated by calling the Dispose method, a


Dispose event occurs.

Elapsed When the interval elapses in timer control, the Elapsed event has occurred.

Tick A tick event is used to repeat the task according to the time set in the
Interval property. It is the default event of a timer control that repeats the
task between the Start() and Stop() methods.
17. Write short notes on vb.net file handling.

 A file is a collection of data stored in computer memory with a specific name and a
defined folder path. The term File Handling in VB.NET is used to perform various
operations like create a file, read a file, write to the file, closing the file, and more.
Furthermore, when a file is opened for reading and writing, a stream is created.
 A stream is a sequence of bytes that passes data to a file to read or write. In VB.NET file
handling, there are two types of stream such as Input Stream or Read
Stream and Output Stream or Write Stream.

VB.Net I/O Classes

 The System.IO namespace has various classes that are used for performing various
operations with files, like creating and deleting files, reading from or writing to a file,
closing a file, etc.
The following table shows some commonly used non-abstract classes in the System.IO
namespace −

I/O Class Description

File It is used to perform some changes in files.

FileInfo It is used to perform any operation on files.

FileStream It is used to apply read or write operations on any location of a file.

BinaryReader As the name represents, a Binary reader is used to read primitive data
in a binary stream.

BinaryWriter It is used to write the data in binary format.

Directory It is used to perform some changes or manipulating a directory


structure.

DriveInfo It helps to provide the necessary information for the drive.

BuffredStream It is a temporary storage area for the collection of steam bytes.

MemoryStream It is used to access stored streaming data in memory.


StreamReader A StreamReader property is used to read characters from the stream
byte.

Path It is used to perform operations on the path of a file.

StreamWriter A StreamWriter is used to write characters to a stream.

DirectoryInfo It is used to perform an operation on the directory.

StringReader It is used to read string from a string buffer.

FileStream Class

 The FileStream class is provided by the System.IO namespace to read, write, close or
create files in the file handling.

The following table is the description of FilesStream Class.

Parameter Description

FileMode The FileMode represents the various method for opening or creating a
file. Following are the member of FileMode-
Append: It is used to open an existing file and put the cursor at the end of
the file. And if the file is not existing, it creates a file.
Create: As the name defines, a create is uses to create a new file.
CreateNew: It specifies the OS to create a new file.
Open: It is used to open an existing file.
OpenOrCreate: It is used to open an existing file, and if the file is not
existing, it creates a new file.
Truncate: It is used to open an existing file for shrinking its original size
to zero bytes.

FileAccess It is used to perform any operation such as Read, ReadWrite, Delete and
Write, etc.

FileShare A FileShare has the following members


Read: It permits to open a file for reading
Write: It permits you to open a file for writing.
None: It is used to reject the sharing of the current file.
Obj_name It represents the object name of the file.

18. Explain inheritance in vb.net.


 In VB.NET, Inheritance is the process of creating a new class by inheriting properties and
functions from the old class and extending the functionality of the existing class. It also
provides a reusable and faster implementation time of the code. When we create a
derived or inherited class, inheritance allows us to inherit all the properties of the existing
class. The old class is known as the baseclass, and the inherited class is known as
the derivedclass.

Inheritance Syntax
 The following is the syntax of Inheritance in VB.NET.

<access_modifier> Class <Name_of_baseClass>


' Implementation of base class
End Class
<access_modifier> Class <Name_of_derivedClass>
Inherits Name_of_baseClass
' Implementation of derived class
End Class

 VB.NET only supports single inheritance that means a class can be inherited from the
base class. However, VB.NET uses hierarchical inheritance to extend one class to another
class, which is called Multi-LevelInheritance .
19. a. What is custom control?
b. What is user control?
c. Differentiate between custom control and user control.
a. custom control is a loosely coupled control defined in a class, which derives from
Control. The UI of the custom control is generally defined in a Resource Dictionary inside
the resource file. They are created according to the requirement of the business .
a. user control The base User Control is nothing but a Custom Control that you derive to
create a control UI specific to your application. It provides the reusability of design and
are created in the same way as a web form.

c. Difference between custom control and user control.

 The main difference between Custom Control and User Control is thatthey inherit from
different levels in the inheritance tree .
 A Custom Control generally inherits from the System.Windows.Controls.Control class.
You may derive from a different custom control depending on your requirement.
 A UserControl inherits from the System.Windows.Controls.UserControls class, which
inherits from the base "Control" class.
20. a. What is ADO.NET?
b. Mention difference between ado.net and ado.
a. -ADO.NET

 ADO.NET is a data access technology from Microsoft .Net Framework , which provides
communication between relational and non-relational systems through a common set of
components . ADO.NET was built for a disconnected architecture , so it enables truly
disconnected data access and data manipulation through its Dataset Object, which is
completely independent from the Data Source.
 The two key components of ADO.NET are Data Providers and DataSet .

.NET Framework Data Providers


 These are the components that are designed for data manipulation and fast access to data.
It provides various objects such as Connection, Command, DataReader and
DataAdapter that are used to perform database operations.
The DataSet

 It is used to access data independently from any data resource. DataSet contains a
collection of one or more DataTable objects of data.
b. Difference between ado and ado.net
 ADO stands for ActiveX Data Objects. In this the programmers use a generic set of objects, no
matter the underlying data sources. It requires locking of database resources and a lengthy
connections for applications. In ADO connection is creating by using a single Connection object.
 ADO.NET:ADO.NET is an advance version of ADO. It interacts with databases and have a
consistent access to various data sources. It does not requires locking and a lengthy connections
for its applications. ADO.NET can have separate objects that represent connections to
different data sources which make access faster and more efficient.
UNIT-3 PROGRAMMING IN VISUAL BASIC.NET
SECTION-A
Two marks questions
1 .What is a data type?

 A Data Type refers to which type of data or value is assigning to a variable or function
so that a variable can hold a defined data type value.

 For example, when we declare a variable, we have to tell the compiler what type of data
or value is allocated to different kinds of variables to hold different amounts of space in
computer memory.
 Syntax:

Dim Variable_Name as DataType

2. What is an operator in VB.NET? List any one operator in VB.NET.

 In VB.NET, operator is a special symbol that tells the compiler to perform the specific
logical or mathematical operation on the data values. The data value itself (which can be
either a variable or a constant) is called an operand, and the Operator performs
various operations on the operand.
 The Arithmetic Operators
o The Arithmetic Operators in VB.NET, used to perform mathematical operations such
as subtraction, addition, multiplication, division, etc. on the operands in VB.NET.
operator
o Eg: The addition Operator –‘ X + Y’
o exponentiation Operator-‘ X^Y’
3. Discuss the scope and lifetime of a variable.

 A Variable’sScope: The scope of a variable is the section of the application that can see
and manipulate the variable. If a variable is declared within a procedure, only the code in
the specific procedure has access to that variable. When the variable’s scope is limited to
a procedure it’s called local.
 Lifetime of a Variable : It is the period for which they retain their value. Variables
declared as Public exist for the lifetime of the application. Local variables, declared
within procedures with the Dim or Private statement, live as long as the procedure.
4 . Explain select case statement with the syntax.

 In VB.NET, the Select Case statement is a collection of multiple case statements, which
allows executing a single case statement from the list of statements. A selected case
statement uses a variable to test for equality against multiple cases or statements in a
program. If the variable is matched with any test cases, that statement will be executed.
And if the condition is not matched with any cases, it executes the default statement.
 Syntax
 Following is the syntax of the Select Case statement in VB.NET, as follows:

Select Case [variable or expression]


Case value1 'defines the item or value that you want to match.
// Define a statement to execute
Case value2 'defines the item or value that you want to match.
// Define a statement to execute
Case Else
// Define the default statement if none of the conditions is true.
End Select

5 .Explain for each….next loop with syntax

 In the VB.NET, For Each loop is used to iterate block of statements in an array or
collection objects. Using For Each loop, we can easily work with collection objects such
as lists, arrays, etc., to execute each element of an array or in a collection. And when
iteration through each element in the array or collection is complete, the control
transferred to the next statement to end the loop.
 Syntax :

For Each var_name As [ DataType ] In Collection_Object


[ Statements to be executed]
Next

6 .Explain use of ‘with …and end with’ with syntax.


 In VB.NET, the With End statement is not the same as a loop structure. It is used to
access and execute statements on a specified object without specifying the name of the
objects with each statement. Within a With statement block, you can specify a member
of an object that begins with a period (.) to define multiple statements.
 Syntax

With objExpression
[ Statements to be Executed]
End With
7. How to use MDI in VB.Net?

 MDI stands for Multiple Document Interface applications that allow users to work with
multiple documents by opening more than one document at a time. Whereas, a Single
Document Interface (SDI) application can manipulate only one document at a time.
 The MDI applications act as the parent and child relationship in a form. A parent form is
a container that contains child forms, while child forms can be multiple to display
different modules in a parent form.
o -With multiple-document interfaces a single menu bar and/or toolbar is shared between
all child windows, reducing clutter and increasing efficient use of screen space.
o -An application's child windows can be hidden/shown/minimized/maximized as a whole.
8. Explain any two built in date functions.
o The Date data type contains date values, time values, or date and time values. The default
value of Date is 0:00:00 (midnight) on January 1, 0001. The equivalent .NET data type
is System.DateTime.
o i.Public Function Add (value As TimeSpan) As DateTime
 Returns a new DateTime that adds the value of the specified TimeSpan to
the value of this instance.
o ii . Public Function AddDays( value As Double) As DateTime
 Returns a new DateTime that adds the specified number of days to the
value of this instance

9. What is purpose of str and val function in string?

 Str()-Returns the string equivalent of a number.


Eg: Str(100) returns "100"

 Val()-Converts a numeric expression to a number.


Eg: Val( (1 + 2 + 3)^2 ) returns 36.
10 .Explain use of user defined function with syntax.

 The function is a separate group of codes that are used to perform a specific task
when the defined function is called in a program. After the execution of a
function, control transfer to the main() method for further execution. It returns a
value.
 Syntax

[Access_specifier ] Function Function_Name [ (ParameterList) ] As Return_Type


1. [ Block of Statement ]
2. Return return_val
3. End Function
 Access_Specifier: It defines the access level of the function such as public,
private, or friend, Protected function to access the method.
 Function_Name : The function_name indicate the name of the function that
should be unique.
 ParameterList: It defines the list of the parameters to send or retrieve data from a
method.
 Return_Type: It defines the data type of the variable that returns by the function.
SECTION-B
Ten marks questions
11. Explain any four different data types with examples in vb.net.

 Data types refer to an extensive system used for declaring variables or functions
of different types. The type of a variable determines how much space it occupies
in storage and how the bit pattern stored is interpreted .

Byte 1 byte 0 through 255 (unsigned)

Char 2 0 through 65535 (unsigned)


bytes

Date 8 0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31,


bytes 9999

Integer 4 -2,147,483,648 through 2,147,483,647 (signed)


bytes

Dim b AsByte
Dim n AsInteger
Dim da AsDate
Dim c AsChar
b =1
n =1234567
da=Today
c ="U"
12. Mention any two decision making statements with syntax with a vb.et program.

 VB.NET provides the following conditional or decision-making statements.


o If-Then Statement
o If-Then Else Statement
o If-Then ElseIf Statement
o Select Case Statement
If-Then Statement
o The If-Then Statement is a control statement that defines one or more conditions, and if
the particular condition is satisfied, it executes a piece of information or statements.
o Syntax:

If condition Then
[Statement or block of Statement]
End If

Module Module1
' Declaration of variable str
Dim str As String = "University"
Sub Main()
' if str equal to "University", below Statement will be executed.
If str = "University" Then
Console.WriteLine("Welcome to the University")
End If
Console.WritLine("press any key to exit?")
Console.ReadKey()
End Sub
End Module
If-Then-Else Statement
o The If-Then Statement can execute single or multiple statements when the condition is
true, but when the expression evaluates to false, it does nothing. So, here comes the If-
Then-Else Statement. The IF-Then-Else Statement is telling what If condition to do
when if the statement is false, it executes the Else statement.
o syntax :

If (Boolean_expression) Then
'This statement will execute if the Boolean condition is true
Else
'Optional statement will execute if the Boolean condition is false
End If

Example:
Write a program to check whether the number is even or odd.

Module If_Else_statement
Sub Main()
Dim num As Integer
Console.WriteLine("Enter the Number")
num = Console.ReadLine() 'read data from console

If (num Mod 2 = 0) Then ' if condition is true, print the if statement


Console.WriteLine("It is an even number")

Else 'otherwise, Else statement is executed.


Console.WriteLine("It is an odd number")
End If

Console.WriteLine("press any key to exit...")


Console.ReadKey()
End Sub
End Module

13. Mention any two looping statements with syntax and example.
o A Loop is used to repeat the same process multiple times until it meets the specified
condition in a program. By using a loop in a program, a programmer can repeat any
number of statements up to the desired number of repetitions.
 Do While Loop
 For Next loop
Do While
o In VB.NET, Do While loop is used to execute blocks of statements in the program, as
long as the condition remains true. In the Do loop, it executes the Do statements, and
then it checks the condition.
o Syntax:

Do
[ Statements to be executed]
Loop While Boolean_expression
// or
Do
[Statement to be executed]
Loop Until Boolean_expression

In the above syntax, the Do keyword followed a block of statements, and While keyword
checks Boolean_expression after the execution of the first Do statement.
Example 1. Write a simple program to print a number from 1 to 10 using the Do While loop in
VB.NET.

Imports System
Module Do_loop
Sub Main()
' Initialization and Declaration of variable i ‘
Dim i As Integer = 1
Do
' Executes the following Statement
Console.WriteLine(" Value of variable I is : {0}", i)
i = i + 1 'Increment the variable i by 1
Loop While i <= 10 ' Define the While Condition

Console.WriteLine(" Press any key to exit...")


Console.ReadKey()
End Sub
End Module

For Next loop


o A For Next loop is used to repeatedly execute a sequence of code or a block of code until
a given condition is satisfied. A For loop is useful in such a case when we know how
many times a block of code has to be executed. In VB.NET, the For loop is also known
as For Next Loop.
o Syntax

For variable_name As [ DataType ] = start To end [ Step step ]


[ Statements to be executed ]
Next
 For: It is the keyword that is present at the beginning of the definition.
 variable_name: It is a variable name, which is required in the For loop Statement. The
value of the variable determines when to exit from the For-Next loop, and the value
should only be a numeric.
 [Data Type]: It represents the Data Type of the variable_name.
 start To end: The start and end are the two important parameters representing the initial
and final values of the variable_name .
 Step: A step parameter is used to determine by which the counter value of a variable is
increased or decreased after each iteration in a program.
 statements: A statement can be a single statement or group of statements that execute
during the completion of each iteration in a loop.
 Next: In VB.NET a Next is a keyword that represents the end of the For loop's

Example 1. Write a simple program to print the number from 1 to 10 using the For Next
loop.
Imports System
Module Number
Sub Main()
' It is a simple print statement, and 'vbCrLf' is used to jump in the next line.
Console.Write(" The number starts from 1 to 10 " & vbCrLf)
' declare and initialize variable i
For i As Integer = 1 To 10 Step 1
' if the condition is true, the following statement will be executed
Console.WriteLine(" Number is {0} ", i)
' after completion of each iteration, next will update the variable counter
Next
Console.WriteLine(" Press any key to exit... ")
Console.ReadKey()
End Sub
End Module
13. Write short notes on Arrays.

VB.NET Arrays
o An array is a linear data structure that is a collection of data elements of the same type
stored on a contiguous memory location. Each data item is called an element of the
array. It is a fixed size of sequentially arranged elements in computer memory with the
first element being at index 0 and the last element at index n - 1, where n represents the
total number of elements in the array.
o Declaration of VB.NET Array
Dim array_name As [Data_Type] ()

o In the above declaration, array_name is the name of an array, and


the Data_Type represents the type of element (Integer, char, String, Decimal) that will to
store contiguous data elements in the VB.NET array.
Example
Dim num As Integer() or Dim num(5) As Integer //Store only Integer values
Dim name As String() or Dim name(5) As String //Store only String values
Dim marks As Double()// Store only Double values

Initialization of VB.NET Array

In VB.NET, we can initialize an array with New keyword at the time of declaration.
Dim num As Integer() = New Integer(5) { }
Dim num As Integer() = New Integer(5) {1, 2, 3, 4, 5, 6}

we can also initialize and declare an array using the following ways, as shown below.

Dim intData() As Integer = {1, 2, 3, 4, 5}


Dim intData(5) As Integer
Dim array_name() As String = {"Peter", "John", "Brock", "James", "Maria"}
Dim misc() as Object = {"Hello friends", 16c, 12ui, "A"c}
Dim Emp(0 to 2) As String
Emp{0} = "Mathew"
Emp(1) = " Anthony"
Emp(2) = "Prince"

Multidimensional Array

o In VB.NET, a multidimensional array is useful for storing more than one dimension in a
tabular form, such as rows and columns. The multidimensional array support two or three
dimensional in VB.NET.
o Declaration of Multidimensional Array
o Representation of Two Dimensional array

Dim twoDimenArray As Integer( , ) = New Integer(3, 2) {}


Or Dim arr(5, 3) As Integer

o Representation of Three Dimensional array

Dim arrThree(2, 4, 3) As Integer


Or Dim arr1 As Integer( , , ) = New Integer(5, 5, 5) { }

 Initialization of Multidimensional Array

' Initialization of Two Dimensional Array


Dim intArray As Integer( , ) = New Integer( 3, 2) { {4, 5}, {2, 3}, {6, 7} }
Dim intArray( , ) As Integer = { {5, 4}, {3, 2}, {4, 7} }
' Initialization of Three Dimensional Array
Dim threeDimen(3, 3, 2 ) As Integer = { {{1, 3, 2}, {2, 3, 4}}, {{5, 3, 6}, {3, 4, 5}}, {{1, 2, 2},
{5, 2, 3} }}

 Fixed Size Array


 In VB.NET, a fixed- size array is used to hold a fixed number of elements in memory.

Dim names( 0 to 4) As String


names(0) = "Robert"
names(1) = "Henry"
names(2) = "Rock"
names(3) = "James"
names(4) = "John"

 The above representation of the fixed array is that we have defined a string array names
0 to 4, which stores all the elements in the array from 0 to index 4 .

14. A.Write a program which uses a function factorial to generate


factorial of a number :
Ans:
Factorial_function.vb
Imports System
Module Factorial_function
' Create a Fact() function
Function Fact(ByVal num As Integer) As Integer
If (num = 0) Then
Return 0
ElseIf (num = 1) Then
Return 1
Else
Return num * Fact(num - 1)
End If
End Function
Sub Main()
' Define the local variable as integer
Dim n, f As Integer
n =5
f=1
f = Fact(n) 'call Fact() function
Console.WriteLine(" Factorial is : {0}", f)
Console.WriteLine(" Press any key to exit...")
Console.ReadKey()
End Sub
End Module

B.Write a function factorial using console application.


Ans
Imports System
Module Program
Sub Main(args As String())
Dim i, number As Integer, fact As Integer = 1
Console.Write("Enter any Number: ")
number = Integer.Parse(Console.ReadLine())

For i = 1 To number
fact = fact * i
Next

Console.Write("Factorial of "& number & " is: "& fact)


Console.ReadLine()
EndSub
EndModule

15. Write short notes on any four vb.net string functions with an example.

 String is defined as the array of characters.


 Declaration and Initialization of string
o Dim Str as String

 Dim: It is the keyword used while declaring any variable.


 Str: It is the name of the variable that will hold the string value.
 String: It is the keyword that is used to state that the value that Str will hold
should be a string.

String Functions

 Format function
This function is used to arrange the string in a particular format.

Example
Input
Dim ChangedTime As Date = #03/23/2019 4:10:43 PM#
Dim ChangedTime as the string
ChangedTime = Format(TestDateTime, "h:m:s")
Output: 04:10:43 PM

 Join function

This VB.Net String function is used to join two substrings.

Example
Input
Dim ItemList() As String = {“Apple”, “Banana”, “Guava”}
Dim JoinItemList as string = Join(ItemList, ", ")
Output: Apple, Banana, Guava

 LCase Function
This function will convert all the characters of the string into a lowercase
character. If the character is already in lowercase that it will ignore the character
else will convert that into lowercase.
Example
Input
Dim Uppercase as String = “HELLO WORLD”
Dim Lowercase as String = LCase(Uppercase)
Output: hello world

 Len function
This String function in VB.Net will return the numbers of characters in a string.
The value returned will be an integer value so it has to be stored in the integer
variable.
Example
Input
Dim StrWords as String = “You are a hero!”
Dim WordCount as Integer = Len(StrWords)
Output: 15

16. Write short notes on any four vb.net mathematical functions with example.

 Math functions are very useful function when we need to perform mathematical
operations such as some trigonometric and logarithmic. To use these math functions
without qualification, import the System.Math namespace .

1. Abs() Function
The Abs Function is used to returns the absolute value of a specified number.

Syntax: Math.Abs(n)
Here, n is the number
This function returns the absolute value.

2. Min() Function
The Min function is used to find out the minimum value from two number.

Syntax
Math.Min(n1, n2)
Here, n1 and n2 are the two number.
This function returns the min value from n1 and n2.

3. Max() Function
The Max function is used to find out the maximum value from two number.
Syntax
Math.Max(n1, n2)
Here, n1 and n2 are the two number. This function returns the maximum value from n1 and
n2.

4. Sqrt() Function
The Sqrt function is used to returns the square root of the number.

Syntax

Math.Sqrt(n1)
Here, n1 is the number.
This function returns the maximum value from n1 and n2.
This function returns a Double value specifying the square root of a number.

The below example describe all of the above function.

Module Module1
Sub Main()
Dim absolute As Integer
absolute = Math.Abs(-16)
Console.WriteLine("The absolute value is: " & absolute)
Dim minimum As Integer
minimum = Math.Min(18, 12)
Console.WriteLine("The minimum value is: " & minimum)
Dim maximum As Integer
maximum = Math.Max(18, 12)
Console.WriteLine("The maximum value is: " & maximum)
Dim square As Integer
square = Math.Sqrt(9)
Console.WriteLine("The square root is: " & square)
End Sub
End Module

17. Write short notes on user defined functions.

 A function is a group of statements that together perform a task when called. After the
function isexecuted, the control returns to the statement calling the function.A function
return a value.
 Defining a Function

The Function statement is used to declare the name, parameter and the body of a function.
The syntax for the Function statement is −

[Modifiers] Function FunctionName [(ParameterList)] As ReturnType

[Statements]

End Function

Where,
o Modifiers − specify the access level of the function; possible values are: Public,
Private, Protected, Friend, Protected Friend and information regarding overloading,
overriding, sharing, and shadowing.
o FunctionName − indicates the name of the function
o ParameterList − specifies the list of the parameters
o ReturnType − specifies the data type of the variable the function returns

Example: a function FindMax that takes two integer values and returns the larger of the two.

Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer


' local variable declaration */
Dim result As Integer
If (num1 > num2) Then
result = num1
Else
result = num2
End If
FindMax = result
End Function

Function Returning a Value

In VB.Net, a function can return a value to the calling code in two ways −
 By using the return statement
 By assigning the value to the function name

The following example demonstrates using the FindMax function


Module myfunctions
Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
' local variable declaration */
Dim result As Integer

If (num1 > num2) Then


result = num1
Else
result = num2
End If
FindMax = result
End Function
Sub Main()
Dim a As Integer = 100
Dim b As Integer = 200
Dim res As Integer

res = FindMax(a, b)
Console.WriteLine("Max value is : {0}", res)
Console.ReadLine()
End Sub
End Module

18. Write short notes on sub Procedure

 Sub procedures are procedures are just like function butt do not return any value

 Defining Sub Procedures

o The Sub statement is used to declare the name, parameter and the body of a sub
procedure. The syntax for the Sub statement is –

[Modifiers] Sub SubName [(ParameterList)]


[Statements]
End Sub

Where,
Modifiers − specify the access level of the procedure; possible values are - Public, Private,
Protected, Friend, Protected Friend and information regarding overloading, overriding,
sharing, and shadowing.
SubName − indicates the name of the Sub
ParameterList − specifies the list of the parameters

Example
The following example demonstrates a Sub procedure CalculatePay that takes two
parameters hours and wages and displays the total pay of an employee −

Module mysub
Sub CalculatePay(ByRef hours As Double, ByRef wage As Decimal)
'local variable declaration
Dim pay As Double
pay = hours * wage
Console.WriteLine("Total Pay: {0:C}", pay)
End Sub
Sub Main()
'calling the CalculatePay Sub Procedure
CalculatePay(25, 10)
CalculatePay(40, 20)
CalculatePay(30, 27.5)
Console.ReadLine()
End Sub
End Module
UNIT-4 ASP.NET BUILDING A WEB APPLICATION

SECTION-A
Two marks questions
1 . List any two properties of button control
o The Button control represents a standard Windows button. It is generally used to
generate a Click event by providing a handler for the Click event.
o Properties of the Button Control
1. AutoSizeMode
Gets or sets the mode by which the Button automatically resizes itself.
2. BackColor
Gets or sets the background color of the control.

2. List any two properties of RichTextBox.


o The RichTextBox control allows the user to display, enter, and edit text while also
providing more advanced formatting features than the
conventional TextBox control.

 BackColor: Gets or sets the background color of the control.

 BorderStyle: Gets or sets the border type of the text box control.

3. Differntiate between panel control and group box control.

 A GroupBox may have a visible caption, whereas the Panel does not.
 A GroupBox always displays a border; a Panel’s border is determined by its BorderStyle
property. It may be set to BorderStyle.None, BorderStyle.Single, or
BorderStyle.Fixed3D.
 A GroupBox does not support scrolling; a Panel enables automatic scrolling when its
AutoScroll property is set to true.

4. List any two methods of form in vb.net.


 Visual Basic Form is the container for all the controls that make up the user interface.
 The following are two of the commonly used methods of the Form class
o Activate:
-Activates the form and gives it focus.

o ActivateMdiChild:
-Activates the MDI child of a form

5. What is a Treeview control? mention any two properties of Treeview control.


o The TreeView control is used to display hierarchical representations of items
similar to the ways the files and folders are displayed in the left pane of the
Windows Explorer. Each node may contain one or more child nodes

Properties of the TreeView Control


o BackColor
Gets or sets the background color for the control.
o BackgroundImage
Gets or set the background image for the TreeView control.

6. What is data binding in vb.net? Mention any two data binding controls.
 The .Net allows powerful feature of data binding, you can bind any server control to
simple properties, collections, expressions and/or methods. When you use data
binding, you have more flexibility when you use data from a database or other means.
 Data binding provides simple, convenient, and powerful way to create a read/write
link between the controls on a form and the data in their application.
 Data binding allows you to take the results of properties, collection, method calls, and
database queries and integrate them with your ASP.NET code
 Data Bind Control can display data in connected and disconnected model.

Following two are among data bind controls in ASP.NET:


 Repeater Control
 DataGrid Control

7. What is ADO.NET?Mention any two advantages of ADO.NET over ADO.


o .Microsoft ActiveX Data Objects.Net (ADO.Net) is a model, a part of the .Net framework
that is used by the .Net applications for retrieving, accessing and updating data.
i. ADO allows you to create client side cursors only whereas ADO.NET gives you the
choice of either using client side or server side cursors.
ii. ADO.Net dataset represents in memory representation of a database. ADO
recordsets is merely a set of rows retrieved from a data source .

8. Mention any one navigation controls and it’s attributes in .net.


o Navigation control in ASP.NET manages the data passing between ASPX pages. Web
applications are having multiple pages interconnected with each other. So proper
navigation system must be there which can help the end user to successfully work
through an application.

Navigation control in ASP.NET:


a) SiteMapPath
 Site maps are XML files which are mainly used to describe the logical
structure of the web application. It defines the layout of all pages in
web application and how they relate to each other. Whenever you want
you can add or remove pages to your site map there by managing
navigation of websiteefficiently. Site map files are defined with
.sitemap extension. <sitemap> element is the root node of the sitemap
file.

It has three attributes:


 Title: It provides textual description of the link.
 URL: It provides the location of the valid physical file.
 Description: It is used for tooltip of the link.

9. What is a Login Control?


 The Login control displays a user interface for user authentication. The Login control
contains text boxes for the user name and password and a check box that allows users
to indicate whether they want the server to store their identity using ASP.NET
membership and automatically be authenticated the next time they visit the site .
 The Login control has properties for customized display, for customized messages,
and for links to other pages where users can change their password or recover a
forgotten password.

10. What is data provider? Explain its components.


 Data Provider is a set of components that facilitate data access. It contains
components like connection, command, dataReader, dataAdapter.
(a) .Connection object connects to the data source.
(b) Command object represents a direct command to the data source.
(c) Data Reader object that provides connected, forward-only, read-only access to
a database.
(d)Data Adapter that provides disconnected data access.

SECTION-B
Ten marks questions
11. A) Describe the PasswordChar, ReadOnly, Multiline ,Text and
WordWrapproperties of textbox.
B) Explain InputBoxfunction with example.

Ans . A)
a)PasswordChar
Gets or sets the character used to mask characters of a password in a single- line
TextBox control.

b)ReadOnly
Gets or sets a value indicating whether text in the text box is read-only.
c ) Multiline
Gets or sets a value indicating whether this is a multiline TextBox control.

d)Text
Gets or sets the current text in the TextBox.

e) WordWrap
Indicates whether a multiline text box control automatically wraps words to the
beginning of the next line when necessary

B) InputBox Function
 In Visual Basic .NET InputBox Function displays a prompt in a dialog box and waits
for the user to write some text and click on the OK button. If the user clicks the OK
button, the InputBox function will returns the contents to the text box. If the user
clicks on the Cancel button, the function will return an empty string ("").

Example:

 The following code shows you the InputBox function. Drag a Button1and
a TextBox control from the toolbox onto the form. Place the code below in the click
event of the Button1.

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)H


andles Button1.Click
Dim str As String = InputBox("Enter you name")
'Storing text entered in a string
TextBox1.Text = str
'Displaying string in the Textbox
End Sub
End Class

12. List any five properties, three methods and two events of ListBox.
The ListBox represents a Windows control to display a list of items to a user. A user can
select an item from the list. It allows the programmer to add items at design time by using the
properties window or at the runtime.

Properties
o AllowSelection
Gets a value indicating whether the ListBox currently enables selection of list items.
o BorderStyle
Gets or sets the type of border drawn around the list box.
o ColumnWidth
Gets of sets the width of columns in a multicolumn list box.
o HorizontalExtent
Gets or sets the horizontal scrolling area of a list box.
o Items
Gets the items of the list box.

Methods
o BeginUpdate
Prevents the control from drawing until the EndUpdate method is called, while items
are added to the ListBox one at a time.
o ClearSelected
Unselects all items in the ListBox.
o EndUpdate
Resumes drawing of a list box after it was turned off by the BeginUpdate method.

Events
o Click
Occurs when a list box is selected.
o SelectedIndexChanged
Occurs when the SelectedIndex property of a list box is changed .

13. A. Mention any five properties of DateTimePicker Control.


B.write the use of ImageList and Tooltip.

Ans: A.
TheDateTimePicker control allows selecting a date and time by editing the displayed
values in the control. If you click the arrow in the DateTimePicker control, it displays a
month calendar, like a combo box control. The user can make selection by clicking the
required date. The new selected value appears in the text box part of the control.

Properties of DateTimePicker

1.BackColor
Gets or sets a value indicating the background color of the DateTimePicker
control.
2.BackgroundImage
Gets or sets the background image for the control.
3.CalendarFont
Gets or sets the font style applied to the calendar.
4.MaxDate
Gets or sets the maximum date and time that can be selected in the control.
5.MinDate
Gets or sets the minimum date and time that can be selected in the control.

B.ImageList Control
 The ImageList is a simple control that stores images used by other controls at
runtime. ImageList is typically used by other controls, such as
the ListView, TreeView, or ToolBar. You can add bitmaps or icons to
the ImageList, and the other controls are able to use the images as they require.
 For example, a TreeView control can use icons to identify its nodes
The simplest and quickest method of preparing these images is to create an ImageList
control and add to it all the icons you need for decorating the TreeView control’s
nodes. The ImageList control maintains a series of bitmaps in memory that the
TreeView control can access quickly at runtime.

Tooltip.
 The ToolTip control is used to display some text when the mouse is move over a
control. This control is helpful in providing quick information when the user moves
the pointer over an associated control.
 Tooltips can be attached to any active element (icons, text links, buttons, etc.) on a
page. They provide descriptions or explanations for their paired element. Thus,
tooltips are highly contextual and specific and don’t explain the bigger picture or
entire task flow.

14. Write a Program to determine items checked in CheckedListBox in VB.net.


program to select or check more than one item from the CheckedListBox in the VB .NET
form.
CheqListvb.vb
Public Class CheqListvb
Private Sub CheqListvb_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = " Books.com"
CheckedListBox1.Items.Add("VB.NET")
CheckedListBox1.Items.Add("Java")
CheckedListBox1.Items.Add("Python")
CheckedListBox1.Items.Add("C")
CheckedListBox1.Items.Add("C#")
CheckedListBox1.Items.Add("PHP")
CheckedListBox1.Items.Add("JavaScript")
CheckedListBox1.Items.Add("Ruby Language")
CheckedListBox1.Items.Add("Android")
CheckedListBox1.Items.Add("Perl")
Label1.Text = "Choose one or more programming languages of your choice. "
Button1.Text = "Select"
Button2.Text = "Exit"
End Sub

' To submit the checked items, click on Button1 or Select


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim cheq As New System.Text.StringBuilder
For Each item In CheckedListBox1.CheckedItems
cheq.Append(item)
cheq.Append(" ")
Next
MessageBox.Show(" Your Checked Items are : " & cheq.ToString())

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


End 'terminate the program
End Sub

In the above list, we can select more than one item from the CheckedListBox in Windows Form.
After that, click on the Select button to display the selected item in Windows Form.

15 . List the build in dialog controls in vb.net. Explain any two of them.

 There are many built- in dialog boxes to be used in Windows forms for various tasks like
opening and saving files, printing a page, providing choices for colors, fonts, page setup,
etc., to the user of an application. These built-in dialog boxes reduce the developer's time
and workload.
 All of these dialog box control classes inherit from the CommonDialog class and override
the RunDialog() function of the base class to create the specific dialog box.

The following diagram shows the common dialog class inheritance –


ColorDialog
 It represents a common dialog box that displays available colors along with controls that
enable the user to define custom colors.
FontDialog
 It prompts the user to choose a font from among those installed on the local computer and
lets the user select the font, font size, and colo r.
OpenFileDialog
 It prompts the user to open a file and allows the user to select a file to open.
SaveFileDialog
 It prompts the user to select a location for saving a file and allows the user to specify the
name of the file to save data
PrintDialog
 It lets the user to print documents by selecting a printer and choosing which sections of
the document to print from a Windows Forms application.

16 .Write notes on TreeView control and TreeNode class. Mention any five properties

 The TreeView control is used to display hierarchical representations of items similar to


the ways the files and folders are displayed in the left pane of the Windows Explorer.
Each node may contain one or more child nodes.

Properties of the TreeView Control


o BackColor
Gets or sets the background color for the control.
o BackgroundImage
Gets or set the background image for the TreeView control.
o BackgroundImageLayout
Gets or sets the layout of the background image for the TreeView control.
o BorderStyle
Gets or sets the border style of the tree view control.
o CheckBoxes
Gets or sets a value indicating whether check boxes are displayed next to the tree
nodes in the tree view control.
o DataBindings
Gets the data bindings for the control.
o Font
Gets or sets the font of the text displayed by the control.
o FontHeight
Gets or sets the height of the font of the control.
o ForeColor
The current foreground color for this control, which is the color the control uses to
draw its text.

The TreeNode Class


 The TreeNode class represents a node of a TreeView. Each node in a TreeView control is
an object of the TreeNode class.

Properties of the TreeNode Class

o BackColor
Gets or sets the background color of the tree node.
o Checked
Gets or sets a value indicating whether the tree node is in a checked state.
o ContextMenu
Gets the shortcut menu that is associated with this tree node.
o ContextMenuStrip
Gets or sets the shortcut menu associated with this tree node.
o FirstNode
Gets the first child tree node in the tree node collection.

UNIT-5 DATABASES
SECTION-A
Two marks questions
1. What is meant by Data Connection Object?
 The connection object is used to open a connection to your database (data source). The
SqlConnectioninstance takes Connection String as argument and pass the value to the
Constructor statement. The Open() method in SqlConnection class is used to open the
Database Connection and The Close() method in SqlConnection class is used to close the
Database Connection.
2. State the difference between data set and data reader.

 The DataSet class in ADO.Net operates in an entirely disconnected nature, while


DataReader is a connection oriented service.
 DataSet is an in-memory representation of a collection of Database objects including
related tables, constraints, and relationships among the tables.It provides a consistent
relational programming model with multiple data sources from different areas.
 DataReader is designed to retrieve a read-only, forward-only stream of data from data
sources. DataReader has a connection oriented nature, whenever you want fetch the data
from database that you must have a connection.
3. What is use of DataGridView? What is difference between DataGrid and
DataGridView?
 DataGridView provides a visual interface to data. It is an excellent way to display and
allow editing for your data. It is accessed with VB.NET code. Data edited in the
DataGridView can then be persisted in the database.
 The DataGrid control is limited to displaying data from an external data source.
The DataGridView control, however, can display unbound data stored in the control, data
from a bound data source, or bound and unbound data together.
4 . What is the use of ExecuteScalar and ExecuteNonQuery in vb.net?
 ExecuteScalar:
Executes the query and returns the first column of first row in result set
returned by query, other columns and rows are ignored by this method.
 ExecuteNonQuery:
we use this operation to execute any arbitrary SQL statements in SQL
Server if you do not want any result set to be returned. we can use this
operation to create database objects or change data in a database by
executing UPDATE, INSERT, or DELETE statements.
5 .What is a DataSet and DataAdapter in vb.net?
 DataSet:
A data set is a collection of related, discrete items of related data that may be
accessed individually or in combination or managed as a whole entity. A data set
is organized into some type of data structure
 DataAdapter:
The DataAdapter works as a bridge between a DataSet and a data source to
retrieve data. DataAdapter is a class that represents a set of SQL commands and a
database connection.
6 .What is LINQ?List any two advantages using LINQ in DataSet.
 The word LINQ is the abbreviation of the Language Integrated Query. It's a .NET
framework module that connects native data querying capabilities to .net Language. It
offers easy data access from in-memory objects, databases, XML documents, and many
more.
Advantages of LINQ
o The primary purpose of using LINQ is to retrieve complex query in a dataset.
o LINQ is used to combine the values from two different data set.
7. What are the different ways to write LINQ query syntax?What is the Query syntax?

 There are two common ways to write a LINQ query to data sources.
-Query syntax or Expression syntax
-Method syntax or method Extension Syntax

o Query syntax is similar to Structured Query Language for the database. It is described
within VB code.
Syntax
from <range variable> in <IEnumerable<T> or IQueryable<T> Collection>
<specific Query Operators> <lambda expression>
<select or groupBy operator> <result formation>

8. Explain LINQ to SQL?

o LINQ to SQL is a part of ADO.NET technologies. It manages the relational data as


an object. LINQ to SQL converts the language integrated query in the object to SQL
and forward them to the database for execution. When the database responses, the
result LINQ to SQL translate them back to objects.
o LINQ to SQL supports user-defined functions and stored procedure in the database.

9. Explain LINQ to XML?


o LINQ to XML provides the in-built document reform capabilities of the DOM
(Document Object Model) and supports LINQ Queries. Using it, we can modify
query, navigate, and save the changes of an XML document. It allows us to write
queries to retrieve and navigate a collection of elements and attributes. It is quite
similar to XPath and XQuery.
10. What are Stored Procedures? Mention any two uses of Stored Procedure.
o A stored procedure is a set of Structured Query Language (SQL) statements with an
assigned name, which are stored in a relational database management system
(RDBMS) as a group, so it can be reused and shared by multiple programs.
Uses
o Stored procedures are often used as access control mechanism and for data validation.
o Procedures are used to process the huge amount of data for complex procedures and
functionalities and for logic implementation access of their data.

SECTION-B
Ten marks questions
11. Explain briefly ADO.NET Architecture. What is a Connection class and Connection
string?
o ADO.NET uses a multilayer architecture that mainly has a few concepts, for instance
Connection, Reader, Command, Adapter and Dataset objects. ADO.NET introduced
data providers that are a set of special classes to access a specific database, execute
SQL commands and retrieve data. The Data providers are extensible. Developers can
create their own providers for a proprietary data source. There are some examples of
data providers such as SQL Server providers, OLE DB and Oracle provider.

ADO.NET provides the following two types of classes objects:

o Connection-based:
They are the data provider objects such as Connection, Command,
DataAdapter, and DataReader. They execute SQL statements and connect
to a database.
o Content-based:
They are found in the System.Data namespace and includesDataSet,
DataColumn, DataRow, and DataRelation. They are completely
independent of the type of data source.

ADO.NET Namespaces

o System.Data:
Contains the definition for columns,relations,tables,database,rows,views
and constraints.
o System.Data.SqlClient:
Contains the classes to connect to a Microsoft SQL Server database such
as SqlCommand, SqlConnection, and SqlDataAdapter.
o System.Data.Odbc:
Contains classes required to connect to most ODBC drivers. These classes
include OdbcCommand and OdbcConnection.
o System.Data.OracleClient:
Contains classes such as OracleConnection and OracleCommand required
to connect to an Oracle database.

Connection Class

Connection class object is used for inserting, updating, deleting and retrieving data from
a database. The Connection class allows you to establish a connection to the data source.
The Connection class object needs the necessary information to discover the data source
and this information is provided by a connection string.

Connection Strings

we need to supply a connection string in the Connection class object. The connection
string is a series of name/value settings separated by semicolons (;). A connection string
requires a few pieces of information such as the location of the database, the database
name, and the database authentication mechanism.

12. Explain ADO.Net data Adapter with an example.

ADO.NET DataAdapter

o The DataAdapter serves as a bridge between a DataSet and a data source for
retrieving and saving data.
o The DataAdapter provides this bridge by mapping Fill, which changes the data in the
DataSet to match the data in the data source, and Update, which changes the data in
the data source to match the data in the DataSet.
o The methods are
 DataAdapter.Fill(DataSet)
 DataAdapter.Fill(DataTable)

o The Fill method retrieves rows from the data source using the SELECT statement
specified by an associated SelectCommand property.
o If the data adapter encounters duplicate columns while populating a DataTable, it
generates names for the subsequent columns, using the pattern "columnname1",
"columnname2", "columnname3", and so on.
From the following program you can understand how to use DataAdapter.Fill method in
VB.NET applications.

Imports System.IO
Imports System.Data.SqlClient
Public Class Form1
Dim cnn As SqlConnection
Dim connectionString As String
Dim sqlAdp As SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataSet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim i As Integer
connectionString = "Data Source=servername; Initial Catalog=databasename;
User ID=userid; Password=password"
cnn = New SqlConnection(connectionString)
cnn.Open()
sqlAdp = New SqlDataAdapter("select * from users", cnn)
cnn.Close() 'connection close here , that is disconnected from data source

sqlAdp.Fill(ds)
sqlAdp.Fill(dt)

'fetching data from dataset in disconnected mode


For i = 0 To ds.Tables(0).Rows.Count - 1
MsgBox(ds.Tables(0).Rows(i).Item(0))
Next

'fetching data from datatable in disconnected mode


For i = 0 To dt.Tables(0).Rows.Count - 1
MsgBox(dt.Tables(0).Rows(i).Item(0))
Next
End Sub
End Class

13. Explain briefly on Data Binding.

DataBinding:
is a powerful feature provided by the .NET Framework that enables visual elements in a
client to connect to a datasource such as DataSets, DataViews, Arrays, etc. Some of the
visual elements in the client can be TextBox, Datagrid, etc. A two-way connection is
established such that any changes made to the datasource are reflected immediately in the
visual element and vice versa.

Advantages of DataBinding

 Databinding in .NET can be used to write data driven applications quickly. .NET data
binding allows you to write less code with fast execution but still get the work done in the
best way.
 .NET automatically writes a lot of databinding code for you in the background (you can
see it in "Windows Generated Code" section), so the developer does not have to spend
time writing code for basic databinding, but still has the flexibility of modifying any code
that he would like to. We get the benefits of bound as well as unbound approach.
 Control over the Databinding process by using events.

14. Explain the following SELECT command ,using WHERE clause,, using ORDERBY
clause with example.

 The SQL SELECT statement is used to fetch the data from a database table which returns
this data in the form of a result table. These result tables are called result-sets.
 Syntax
The basic syntax of the SELECT statement is as follows −
SELECT column1, column2, columnN FROM table_name;
Example:SELECT * FROM table_name;

 The SQL WHERE clause is used to specify a condition while fetching the data from a
single table or by joining with multiple tables. If the given condition is satisfied, then
only it returns a specific value from the table
 Syntax
The basic syntax of the SELECT statement with the WHERE clause is as shown below.
SELECT column1, column2, column FROM table_name
WHERE [condition]
Example: SELECT ID, NAME, SALARY
FROM CUSTOMERS
WHERE SALARY > 2000;

 The SQL ORDER BY clause is used to sort the data in ascending or descending order,
based on one or more columns.
 Syntax
The basic syntax of the ORDER BY clause is as follows −
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, ..columnN] [ASC | DESC];

 Example:SELECT * FROM CUSTOMERS


ORDER BY NAME, SALARY;

15. A. What is LINQ? Mention any advantages LINQ. What are the types of LINQ?

 LINQ (Language Integrated Query) is uniform query syntax in C# and VB.NET to


retrieve data from different sources and formats. It is integrated in C# or VB, thereby
eliminating the mismatch between programming languages and databases, as well as
providing a single querying interface for different types of data sources .

Advantages

 LINQ offers a common syntax for querying any type of data sources
 it binds the gap between relational and object-oriented approachs.
 LINQ expedites development time by catching errors at compile time and includes
IntelliSense & Debugging support
 LINQ expressions are Strongly Typed..

Types of LINQ

 LINQ To Objects
The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or
IEnumerable<T> collection directly, without the use of an intermediate LINQ provider or
API such as LINQ to SQL or LINQ to XML.

 LINQ To DataSets
LINQ to DataSet makes it easier and faster to query over data cached in a DataSet object.
Specifically, LINQ to DataSet simplifies querying by enabling developers to write
queries from the programming language itself, instead of by using a separate query
language.
 LINQ To SQL
LINQ to SQL fully supports transactions, views, and stored procedures. It also provides
an easy way to integrate data validation and business logic rules into your data model.
This example defines the basic idea of LINQ to SQL Query using code.

 LINQ to XML
LINQ to XML is an in-memory XML programming API designed specifically to take
advantage of Language-Integrated Query (LINQ).

You might also like