3 Unit C#
3 Unit C#
Editor Window or Main Window: Here, you will work with forms and code editing. You can notice the
layout of form which is now blank. You will double click the form then it will open the code for that.
Solution Explorer Window: It is used to navigate between all items in solution. For example, if you will
select a file form this window then particular information will be display in the property window.
Properties Window: This window is used to change the different properties of the selected item in the
Solution Explorer. Also, you can change the properties of components or controls that you will add to the
forms.
Now to add the controls to your WinForms application go to Toolbox tab present in the extreme left side of
Visual Studio. Here, you can see a list of controls. To access the most commonly used controls go to Common
Controls present in Toolbox tab.
To run the program you can use an F5 key or Play button present in the toolbar of Visual Studio. To stop the
program you can use pause button present in the ToolBar. You can also run the program by going to Debug-
>Start Debugging menu in the menubar.
Timer
The timer control is a looping control used to repeat any task in a given time interval. 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.
Property Meaning
Enabled Gets/sets whether the timer is running.
Interval Gets/sets the time in milliseconds between timer ticks.
88
Method Meaning
Start Starts the timer.
Stop Stops the timer.
Steps
Code/Program:
PictureBox
PictureBox control is used to display the images on Windows Form. The PictureBox control has an image
property that allows the user to set the image at runtime or design time.
Typically the PictureBox is used to display graphics from a bitmap, metafile, icon, JPEG, GIF, or PNG file.
Example: While applying for any exams through online you upload image into google form.
Properties of Picturebox
89
Image - The image property is used to display the image on the PictureBox of a Windows form.
BorderStyle- It is used to set the border style for the picture box in the windows form.
ImageLocation-It is used to set or get the path or URL of the image displayed on the picture box of
the window form.
Text - It is used to set text for the picture box controls in the window form.
Methods of Picturebox
GetStyle() - The GetStyle() method is used to get values for the specified bit style in the PictureBox
control.
Load() - The Load() method is used to load the specified image from the control using the
ImageLocation property.
Events of Picturebox
BackColorChanged - It occurs when the property of the backcolor is changed in the PictureBox
control.
Resize - The resize event occurs when the picture box control is changed.
Steps
Step 1: We have to find the PictureBox control from the toolbox and then drag and drop the PictureBox
control onto the window form, as shown below.
Step 2: Once the PictureBox is added to the form, we can set various properties of the image by clicking on
the PictureBox control. And double click on the button write the below given code.
In the code we need to specify the path of the image that is to be displayed
Output:
1. The ComboBox control is used to display a drop-down list of various items. It is a combination of a
text box in which the user enters an item and a drop-down list from which the user selects an item. An
editable text field, giving the user multiple ways to input or select the desired information.
2. The ListBox control enables you to display a list of items to the user that the user can select by
clicking.
Properties of Combobox
MaxDropDownItems - The MaxDropDownItems property is used in the combo box control to
display the maximum number of items by setting a value.
MaxLength - It is used by the user to enter maximum characters in the editable area of the combo
box.
SelectedItem - It is used to set or get the selected item in the ComboBox Control.
Sorted - The Sorted property is used to sort all the items in the ComboBox by setting the value.
Events of ComboBox
FontChanged - It occurs when the property of the font value is changed.
Format - When the data is bound with a combo box control, a format event is called.
SelectIndexChanged - It occurs when the property value of SelectIndexChanged is changed.
Steps:
Step 1: We need to drag the combo box control from the toolbox and drop it to the Windows form, as shown
below.
Step 2: Once the ComboBox is added to the form, we can set various properties of the ComboBox by clicking
on the ComboBox control.Also drag and drop listbox and buttons .Write the code as given below
91
End If
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ComboBox1.Items.Clear()
ComboBox1.Items.Add("TROUSERS")
ComboBox1.Items.Add("TSHIRTS")
ComboBox1.Items.Add("JACKETS")
ComboBox1.Items.Add("JEANS")
ComboBox1.Text = "CLOTHING"
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
Handles ComboBox1.SelectedIndexChanged
Label1.Text = ComboBox1.SelectedItem.ToString()
End Sub
Listbox
GroupBox
In Windows form, GroupBox is a container which contains multiple controls on it and the controls are related
to each other. Or in other words, GroupBox is a frame display around a group of controls with a suitable
optional title. Or a GroupBox is used to categorize the related controls in a group.
The main use of a group box is to hold a logical group of RadioButton controls.
Properties of Groupbox:
AutoSize -This property is used to get or set a value that indicates whether the control resizes based
on its contents.
AutoSizeMode - This property indicates how the GroupBox behaves when its AutoSize property is
enabled.
BackColor - This property is used to get or set the background color for the control.
BorderStyle -This property indicates the border style for the control.
Size - This property is used to get or set the height and width of the control.
Visible - This property is used to get or set a value indicating whether the control and all its child
controls are displayed.
Width - This property is used to get or set the width of the control.
Steps
92
To create a GroupBox control at design-time, you simply drag and drop a GroupBox control from
Toolbox to a Form in Visual Studio. After you drag and drop a GroupBox on a Form. Once a
GroupBox is on the Form, you can move it around and resize it using mouse and set its properties and
events.
Also drag and drop radiobuttons and button user needs to select the option from given courselist and
submit.
Output:
Groupbox
Scrollbars
Vertical scrollbar
Horizontal scrollbar
A ScrollBar control is used to create and display vertical and horizontal scroll bars on the Windows form. It is
used when we have large information in a form, and we are unable to see all the data. Therefore, we used
VB.NET ScrollBar control. Generally, ScrollBar is of two types: HScrollBar for displaying scroll bars and
VScrollBar for displaying Vertical Scroll bars.
Properties of Scrollbars
BackColor - The BackColor property is used to set the back color of the scroll bar.
Maximum - It is used to set or get the maximum value of the Scroll Bar control. By default, it is 100.
Minimum - It is used to get or set the minimum value of the Scroll bar control. By default, it is 0.
Value- It is used to obtain or set a value in a scroll bar control that indicates a scroll box's current
position.
Events of scrollbars
Scroll - Occurs when the scroll box is moved either using mouse or keyboard.
93
ValueChanged - Occurs when the value property has changed by Scroll event or in code
Steps
Step 1: The first step is to drag the HScrollBar and VScrollBar control from the toolbox and drop it on to the
form.
Step 2: Once the ScrollBar is added to the form, we can set various properties of the ScrollBar by clicking on
the HScrollBar and VScrollBar control. Write the code as given below
Me.HScrollBar1.Minimum = 0
Me.HScrollBar1.Maximum = 100
Me.HScrollBar1.Value = 35
End Sub
End Class
NumericUpDown
The Windows Forms NumericUpDown control looks like a combination of a text box and a pair of arrows that
the user can click to adjust a value. The control displays and sets a single numeric value from a list of choices.
Example: If we want to enter our age in google form numericupdown is used.
1. DecimalPlaces: Gets or sets the number of decimal places to display in NumericUpDown Control.
2. UpDownAlign: Set positions the arrow buttons on the left or the right side of the NumericUpDown.
Default value is Right.
Steps
To create a NumericUpDown control at design-time, you simply drag and drop a NumericUpDown
control from Toolbox to a Form in Visual Studio.
Once a NumericUpDown is on the Form, you can move it around and resize it using mouse and set its
properties and events.Drag a button and double click on the button write the below code.
The ToString method is used to return a string representation of an object.
String format() method returns a formatted string using the given locale, specified format string, and
arguments
Code/Program :
94
Output:
ProgressBar
The ProgressBar control is typically used when an application performs tasks such as copying files or printing
documents.
The Window ProgressBar control is used by the user to acknowledge the progress status of some defined
tasks, such as downloading a large file from the web, copying files, installing software, calculating complex
results, and more.
The main properties of a progress bar are Value, Maximum and Minimum. The Minimum and Maximum
properties are used to set the minimum and maximum values that the progress bar can display. The Value
property specifies the current position of the progress bar.
Properties of Progressbar
Maximum - It is used to set the maximum length of the progress bar control in the windows form.
Minimum - It is used to set or get the minimum value of the progress bar control in the windows
form.
Padding - The padding property is used to create a space between the edges of the progress bar by
setting the value in the progressbar control.
Events of ProgressBar
Leave - The Leave event occurs when the focus leaves the progress bar control.
MouseClick - A MouseClick event occurred when the user clicked on the progress bar control by the
mouse.
Methods of ProgressBar:
ForeColor - The ForeColor method is used to reset the forecolor to its default value.
ToString - The ToString method is used to display the progress bar control by returning the string.
Increment - It is used to increase the current state of the progress bar control by defining the specified
time.
Steps
Step 1: The first step is to drag the ProgressBar control from the toolbox and drop it on to the Form.
Step 2: Once the ProgressBar is added to the Form, we can set various properties of the ProgressBar by
clicking on the ProgressBar control. Drag a button so that when user click on button starts downloading
Code/Program:
Public Class Progressbar
95
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ProgressBar1.Visible = True
Dim i As Integer
ProgressBar1.Minimum = 0
ProgressBar1.Maximum = 100
End If
Next
MsgBox("Successfully Completed")
End Sub
End Class
Output:
TrackBar
The Windows Forms TrackBar control (also sometimes called a "slider" control) is used for navigating
through a large amount of information or for visually adjusting a numeric setting. The TrackBar control has
two parts: the thumb, also known as a slider..
Example: Phone Brightness, Youtube videos.
Properties
The key properties of the TrackBar control are Value, TickFrequency, Minimum, and Maximum.
TickFrequency is the spacing of the ticks. Minimum and Maximum are the smallest and largest values
that can be represented on the track bar. Two other important properties are SmallChange and
LargeChange.
The value of the LargeChange property is the number of positions the thumb moves in response to
having the PAGE UP or PAGE DOWN key pressed, or in response to mouse clicks on the track bar
on either side of the thumb.
Steps
Step1:To create a TrackBar control at design-time, you simply drag and drop a TrackBar control from
Toolbox to a Form in Visual Studio. After you drag and drop a TrackBar on a Form,
Step2: You can configure ranges through which the value of the Value property of a track bar scrolls by
setting the Minimum property to specify the lower end of the range and the Maximum property to specify the
upper end of the range.
96
Code/Program:
End Sub
End Class
Output:
PROCEDURE
SUBROUTINE FUNCTION
DOES NOT RETURN VALUE RETURNS A VALUE TO CALLING
TO CALLING FUNCTION FUNCTION
Subroutine
A Sub procedure also called as subroutine is a separate set of codes that are used in VB.NET programming to
execute a specific task, when it is called and it does not return any values. The Sub procedure is enclosed by
the Sub and End Sub statement. The Sub procedure is similar to the function procedure for executing a
specific task except that it does not return any value, while the function procedure returns a value.
97
Sub Main()
Dim a As Integer = 100
Dim b As Integer = 200 ' local variable definition
swap(a, b) ' calling a function to swap the values '
Console.WriteLine("After swap, value of a : {0}", a)
Console.WriteLine("After swap, value of b : {0}", b)
Console.ReadLine()
End Sub
End Module
Pass by Reference
Refer same above program instead ByVal put ByRef
Module paramByval
Sub swap(ByVal x As Integer, ByVal y As Integer)
Dim temp As Integer
temp = x
x=y
y = temp
End Sub
Sub Main()
Dim a As Integer = 100
Dim b As Integer = 200 ' local variable definition
swap(a, b) ' calling a function to swap the values '
Console.WriteLine("After swap, value of a : {0}", a)
Console.WriteLine("After swap, value of b : {0}", b)
Console.ReadLine()
End Sub
End Module
Functions
A function procedure is a group of VB.NET statements. It begins with a Function keyword and ends with an
End Function keyword. It is generally used to perform a task and return a value back to the calling code. It has
return keyword .
Subroutines usually perform actions and they don't return any result. Functions, on the other hand, perform
some calculations and return a value.
There are two types of Functions:
1. User-Defined
2. Built-in functions
Syntax for Functions:
[Modifiers] Function FunctionName [(ParameterList)] As ReturnType
[Statements]
End Function
Program:
Passing by Value
Module Find_Sum
' Create the Sum() Function and pass the parameters.
Function Sum(ByVal n1 As Integer, ByVal n2 As Integer) As Integer
Dim sum As Integer = 0
sum = n1 + n2
Return sum
End Function
Dim a As Integer = 50
Dim b As Integer = 20
Dim total As Integer
98
Console.WriteLine(" Sum of two number is : {0}", total)
Console.ReadKey()
End Sub
End Module
Passing By Reference
Refer same above program instead ByVal put ByRef
Module Find_Sum
' Create the Sum() Function and pass the parameters.
Function Sum(ByRef n1 As Integer, ByRef n2 As Integer) As Integer
sum = n1 + n2
Return sum
End Function
Dim a As Integer = 50
Dim b As Integer = 20
Dim total As Integer
Visual Basic has many built-in functions for manipulating text and carrying out mathematical operations, as
well as the ability to format data in both standard and user-defined styles.
Some of the built-in functions are explained below:
MsgBox() Function
The MsgBox() function displays a message in a pop-up message box . The user is expected to respond by
clicking on a button in order to be able to continue.
returnVal = MsgBox (prompt, styleVal, title)
The prompt parameter is a string value that supplies the message to be displayed.
The returnVal value returned by the MsgBox() function is an integer value that indicates which button
the user has clicked in response to the message box being displayed.
The title parameter is another string literal or string variable that supplies the title for the message box.
Example: MsgBox(messageText.Text, vbYesNo Or vbQuestion)
vbOkOnly Ok
vbYesNo Yes,No
vbOkCancel Ok,Cancel
vbAbort Abort
vbRetry Retry
vbYesNoCancel Yes,No,Cancel
vbIgnore Ignore
vbRetryCancel Retry,Cancel
99
InputBox() Function
The InputBox() function displays a pop-up input box into which the user can type a message. The user is
expected to enter their message, then click on a button ("Cancel" or "OK") in order to continue.
The returnString returned by the InputBox() function is the text entered by the user.
The defaultText parameter can be used to enter default content in the input box (although it would
probably be left blank in most cases).
The xpos and ypos parameters specify the x and y coordinates for the input box on screen.
String Functions
UCase (str) Converts the string referred to by str to all upper-case characters, and returns the result.
LCase (str) Converts the string referred to by str to all lower-case characters, and returns the result.
Trim (str) Removes the white space (if any) at either end of the text string referred to by str .
LTrim (str) Removes the white space (if any) at the left-hand end of the text string referred to by str
RTrim (str) Removes the white space (if any) at the right-hand end of the text string referred to by str
Maths functions
Formatting numbers
The Format() function allows you to specify precisely how numeric values are displayed. The function is used
as follows:
100
Percent Displays n as a percentage, rounds it up (or down) to
two decimal places, and adds a "%" symbol.
The Format() function can also be used to specify how date and time values are displayed. The function is
used as follows:
"General Date" Displays the date and time in the format: dd/mm/yyyy hh:mm:ss
"Long Date" Displays the date in the format: 06 October 2009
"Short Date" Displays the date in the format: dd/mm/yyyy
"Long Time" Displays the time in the format: h:mm:ss
Database Applications
Database systems are designed to manage large bodies of information. Management of data involves both
defining structures for storage of information and providing mechanisms for the manipulation of information.
Databases are useful in many different scenarios for storing data. It is typical to use a database when different
sets of data needs to be linked together, such as:
Database Applications:
By filling the required details we are able to access social media platforms. Many users
sign up daily on social websites such as Facebook, Pinterest and Instagram. All the information related to the
users are stored and maintained with the help of DBMS.
Now-a-days there are lots of things to do with finance like storing sales, holding information and
finance statement management etc. these all can be done with database systems.
In military areas the DBMS is playing a vital role. Military keeps records of soldiers and it has so
many files that should be kept secure and safe. DBMS provides a high security to military information.
Now-a-days we all do Online shopping without wasting the time by going shopping with
the help of DBMS. The products are added and sold only with the help of DBMS like Purchase information,
invoice bills and payment.
Banking is one of the main applications of databases. We all know there will be a thousand
transactions through banks daily and we are doing this without going to the bank. This is all possible just
because of DBMS that manages all the bank transactions.
Manufacturing companies make products and sell them on a daily basis. To keep records of
all those details DBMS is used.
Just like the railway reservation system, airlines also need DBMS to keep
records of flights arrival, departure and delay status.
101
Library Management System -a- in the Library to track each book and maintain
it because of the database. This happens because there are thousands of books in the library. It is very difficult
to keep a record of all books in a copy or register. Now DBMS used to maintain all the information related to
book issue dates, name of the book, author and availability of the book.
1. Accurate
A database is pretty accurate as it has all sorts of build in constraints, checks etc. This means that the
information available in a database is guaranteed to be correct in most cases.
3. Security of data
Databases have various methods to ensure security of data. There are user logins required before
accessing a database and various access specifiers. These allow only authorised users to access the
database.
4. Data integrity
This is ensured in databases by using various constraints for data. Data integrity in databases makes
sure that the data is accurate and consistent in a database.
ADO.NET Connectivity
INTRODUCTION TO ADO.NET
ADO.NET stands for ActiveX Data Object is a large set of .NET classes that enable us to retrieve
and manipulate data, and update data sources, in very many ways.
ADO.NET is a bridge between the user application(frontend) and server(backend).Data coming from
application must be stored in database and ADO.NET provides various classes to store the data.
It is a module of .Net Framework which is used to establish connection between application and data
sources. Data sources can be such as SQL Server and XML. ADO.NET consists of classes that can be
used to connect, retrieve, insert and delete data.
All the ADO.NET classes are located into System.Data.dll and integrated with XML classes located
into System.Xml.dll.
102
ADO.NET has two main components that are used for accessing and manipulating data are the .NET
Framework data provider and the DataSet.
Dataprovider A .NET Framework data provider is used for connecting to a database, executing
commands, and retrieving results.
Dataset The DataSet, which is an in-memory cache of data retrieved from a data source, is a major
component of the ADO.NET architecture
DataProvider
ADO vs ADO.NET
ADO ADO.NET
o It is a COM(Component Object o It is a CLR(Common Language Runtime)
Modelling) based based Library.
o Library.
o Locking features is available o Locking features is not available
o ADO works in the connected mode to o ADO.Net works in the disconnected
access data mode to access data.
o Data is stored in Binary Format o Data is stores in XML
o XML integration is not possible o XML integration is possible
o It uses RecordSet to store the data from o It uses Dataset to store the data from
datasource datasource
o Using classic ADO, you can obtain o Dataset object of ADO.Net includes
information from one table or set of collection of DataTable wherein each
tables through join. You cannot fetch DataTable will contain records fetched
records from multiple tables from a particular table. Hence multiple
independently table records are maintained
independently
103
o In ADO, You can create only Client side o In ADO.Net, You can create both Client
cursor. & Server side cursor
o Firewall might prevent execution of o ADO.Net has firewall proof and its
Classic ADO execution will never be interrupted
o You cannot send multiple transaction o You can send multiple transaction using
using a single connection instance a single connection instance.
o ADO requires data to be converted to o ADO.NET does not require complex
data types supported by receiving system. conversions that wasted processor time.
o It has a less number of data types o It has a huge and rich collection of data
types.
o ADO is less secured. o ADO.NET much secured as compared to
ADO.
o ADO technology have less scalable. o ADO.NET have more scalability with the
use of locking mechanism.
o ADO have a poor performance. o In ADO.NET performance is much better
as compared to ADO.
o ADO technology use more resources as o ADO.NET conserves limited resources.
compared to ADO.NET.
Architecture of ADO.NET
It is a part of the .NET Framework which is used to establish a connection between the .NET Application and
different data sources. So, ADO.NET is nothing but a component in .NET Framework that helps us to fetch
data from different data sources(server) as well as also used to send data to different data sources(server) such
as SQL Server, Oracle, MySQL, XML, etc
The ADO.NET architecture comprises following important components. They are as follows:
1. Connection
104
2. Command
3. DataReader
4. DataAdapter
5. DataSet
Diagram
Dataprovider: It is a bridge between the user application and database. Data provider is used to connect to the
database, execute commands and retrieve the record. It is lightweight component with better performance.
They are the Microsoft SQL Server Data Provider , OLEDB Data Provider and ODBC Data Provider . SQL
Server uses the SqlConnection object , OLEDB uses the OleDbConnection Object and ODBC uses
OdbcConnection Object respectively.
Connection: The connection object is the first important component of your application. It is required to
connect to a backend database that may be SQL Server, Oracle, MySQL, etc. The connection is created using
the connection object and a backend data source must be connected to using the connection. To use this class,
you have to first create an object of this class. Hence, here we create a variable called 'cnn' which is of the type
SqlConnection.
Command: The second important component is the command object. When we discuss databases such as
SQL Server, Oracle, MySQL, then speak SQL, it is the command object that we use to create SQL queries.
After you create your SQL queries, you can execute them over the connection using the command object.
Example: select * FROM customers;
105
DataReader: We can only read the records in the forward mode with DataReader. Here, you should
familiarize yourself with three things: read-only, connected, and forward modes. The DataReader cannot be
created directly from code, they can created only by calling the ExecuteReader method of a Command Object.
The DataReader is a good choice when you're retrieving large amounts of data because the data is not cached
in memory.
reader = command.ExecuteReader();
DataSet: It is a Disconnected record set that can be browsed in both i.e. forward and backward mode. It is not
read-only i.e. you can update the data present in the data set. Actually, DataSet is a collection of DataTables
that holds the data and we can add, update, and delete data in a data table. DataSet gets filled by somebody
called DataAdapter. For example, the test scores of each student in a particular class is a data set.
DataAdapter: A data adapter a object serves as a bridge between a data set object and Data Source such as a
database to retrieve and save the data. Data adapter contains a set of database commands and a database
connection, which we use to fill a dataset object and update the Data Source.
DataReader
This class is used to read data from SQL Server database. We can only read the records in the forward mode
with DataReader. Here, you should familiarize yourself with three things: read-only, connected, and forward
modes. The DataReader cannot be created directly from code, they can created only by calling the
ExecuteReader method of a Command Object.
Properties
106
Connection It is used to get the SqlConnection associated with the
SqlDataReader.
Depth It is used to get a value that indicates the depth of nesting for the
current row.
GetValue(Int32) It is used to get the value of the specified column in its native format.
To create a SqlDataReader instance, we must call the ExecuteReader method of the SqlCommand object.
reader = command.ExecuteReader();
Program:
{
using (connection)
{
SqlCommand command = new SqlCommand( "SELECT CategoryID, CategoryName FROM
Categories;",connection);
connection.Open(); //connection open
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}\t{1}", reader.GetInt32(0),
reader.GetString(1));
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
conn.Close(); //connection close
}
Data Adapter
107
A data adapter a object serves as a bridge between a data set object and Data Source such as a database to
retrieve and save the data.Data adapter contains a set of database commands and a database connection, which
we use to fill a dataset object and update the Data Source.
We can also specify, which action we want to perform by using one of following four data adapter properties,
which executes a SQL statement.
The properties are given below.
Select command retrieves rows from Data Source
Insert command writes inserted rows from data set into Data Source
Update command writes modified rows from data set into Data Source.
Delete command deletes rows from Data Source.
Methods of DataAdapter:
FillUse this method of a SQL data adapter to add or refresh row from a Data Source and place them in
a Data Set table.
UpdateUse this method of data adapter object to transmit the changes to a dataset table to the
corresponding Data Source.
CloseUse this method for the connection to a database
Code/Program:
public partial class DataSetDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("data source=.; database=student; integrated
security=SSPI"))
{
SqlDataAdapter sde = new SqlDataAdapter("Select * from student", con);
DataSet ds = new DataSet();
sde.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
}
}
108
Data Adapters: It communicate between a data source and dataset. We can use OleDbAdapter,
OdbcAdapter, Oracle Adapter or SqlAdapter.
Command Objects: Data adapters can read, write, add, update and delete the records in a datasource. Data
adapters support 4 properties SelectCommand, InsertCommand, DeleteCommand, UpdateCommand.
Dataset: The structure of a dataset is similar to relational database. It gives you access to an object model of
tables, rows and columns.
Data Table: It holds a data table from a data source. It contain two properties: Columns and rows which is
collection of Datacolumn and Datarow objects.
Data Reader: It hold a read only, forward only.
Data Views: It represent a customized view of a single table that can be filtered, searched or sorted.
Constraint Objects: Dataset supports constraint to check data integrity. Ex: Unique constraint and foreign
constraint
Data Relation Objects: It specify a relationship between parent and child tables based on a key that share.
Data Row/Column: A particular row/column in a data table
Joining Tables
We can to inner join, outer join using multiple tables.
ASP.NET
Programming web applications with web forms/ASP.NET applications with ADO.NET:
109
ASP.NET is a free web framework for building great websites and web applications using HTML, CSS,
and JavaScript.
ASP.NET is a web development platform, which provides a programming model, a comprehensive
software infrastructure and various services required to build up robust web applications for PC, as
well as mobile devices.
ASP.NET is a part of Microsoft .Net platform. ASP.NET applications are compiled codes, written using
the extensible and reusable components or objects present in .Net framework. These codes can use the
entire hierarchy of classes in .Net framework.
The ASP.NET application codes can be written in any of the following languages:
C#
Visual Basic.Net
Jscript
Web Forms:
Web Forms are pages that your users request using their browser. These pages can be written using a
combination of HTML, client-script, server controls, and server code. When users request a page, it is
compiled and executed on the server by the framework, and then the framework generates the HTML
markup that the browser can render. An ASP.NET Web Forms page presents information to the user in
any browser or client device.
Using Visual Studio, you can create ASP.NET Web Forms. The Visual Studio Integrated Development
Environment (IDE) lets you drag and drop server controls to lay out your Web Forms page. You can
then easily set properties, methods, and events for controls on the page or for the page itself. To write
server code to handle the logic for the page, you can use a .NET language like Visual Basic or C#.
ASP.NET has multiple features and provides many tools to create and develop web applications. Here
are some of the features of web forms:
1. Server Controls
It provides a vast set of server controls. These controls are like objects, and they run when they are
requested and rendered to the browser. Some web pages are similar to HTML elements like text-box,
button, checkbox, and hyperlink.
2. Mater Pages
Mater Pages is responsible for the consistent layout of our web applications. It gives a proper
appearance and standard to different pages.
3. Routing
110
URL routing can be configured to a web application. A request URL is a URL that a user enters in a
browser to browse in a specific place.
4. Security
Security always plays a crucial role in software development. ASP.NET provides different configuration
options and extensibility points to make our systems more secure.
Simple Example of Web Forms[should be written if any question asked upon ASP.NET]
Creating New Web Forms
To add a new form, select the project, right-click, and add a new item.
Click the web forms option in the left corner, and select web form.
Now click on the add button.
Double click on this form, and this will show some auto-generated code
111
Program:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<h1 style="text-align: center">Create Account</h1>
</div>
<table>
<tr>
<td>Enter Username:
</td>
<td>
<asp:TextBox ID="txtUserNameAC" runat="server" />
<asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please
enter Username" ControlToValidate="txtUserNameAC" runat="server" />
</td>
</tr>
<tr>
<td>Enter Password:
</td>
<td>
ControlToValidate="txtPWDAC" ErrorMessage="Please enter Password" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="createAccountSubmit" runat="server" Text="Create
Account" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
112
cmd.Parameters.AddWithValue("@username", TextBox1.Text);
cmd.Parameters.AddWithValue("@Password", TextBox2.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("LoginPage.aspx");
}
else
{
Label3.Visible = true;
Label3.Text = "Wrong Details";
}
******GOOD LUCK******
-------------------------------------------------------------------------------------------------------------------------------------
113