Core Idea
.NET is Microsoft’s unified, cross-platform development platform that provides a managed runtime (CLR), language interoperability, and a rich class library for building modern applications.
1. Evolution of .NET
2-Mark Version
- Microsoft platform for building and running applications.
- Announced in 2000; first release (.NET 1.0) in 2002.
- Evolution: .NET Framework → .NET Core (open-source, cross-platform) → unified .NET 5/6/7/8.
- Solved major COM/DCOM problems: DLL Hell, language lock-in, and security issues.
Long Answer Points
- Pre-.NET era suffered from COM registration, versioning hell, and language dependency.
- .NET Framework introduced managed code, CLR, and CTS.
- From 2015: Microsoft made .NET Core open-source for Windows, Linux, and macOS.
- Current state: Single unified .NET platform (no separate Framework/Core branches).
2. Components of .NET
Key Components
- CLR – Common Language Runtime (execution engine)
- CTS – Common Type System
- CLS – Common Language Specification
- BCL/FCL – Base Class Library / Framework Class Library
- Languages: C#, VB.NET, F#
- Frameworks: ASP.NET, ADO.NET, WinForms, WPF
Visual Hierarchy
Languages (C#, VB.NET, F#)
↓
CLS + CTS
↓
CLR (JIT + GC + Security + EH)
↓
Base Class Library
3. CLR – Common Language Runtime
2-Mark Version
CLR is the runtime engine that manages code execution. It provides JIT compilation, automatic memory management, security, and exception handling.
Important Features
| Feature | Description | Mnemonic |
|---|---|---|
| JIT Compilation | Converts MSIL to native code at runtime | J |
| Garbage Collection | Automatic memory management | G |
| Exception Handling | Structured error handling across languages | E |
| Code Access Security | Controls permissions of running code | S |
| Thread Management | Supports multithreading | T |
| Type Safety | Verifies type compatibility | T |
| Metadata & Reflection | Runtime inspection of code | — |
Mnemonic: J-GET-SET
4. CLS – Common Language Specification
- CLS is a subset of CTS.
- Defines rules that languages must follow for interoperability.
- Enables code written in one .NET language to be used in another (e.g., C# class inherited in VB.NET).
- Any assembly following CLS rules is called CLS-compliant.
5. Assemblies (DLL/EXE) in .NET
2-Mark Version
An assembly is a compiled unit (DLL or EXE) containing MSIL, metadata, and resources. It is self-describing and does not require registry registration.
Key Points
- Can be private or shared (stored in GAC)
- Contains MSIL + Metadata + Manifest
- Solves DLL Hell through strong naming and versioning
- Self-describing (no external type library needed)
Quick Reference Table
| Term | Full Form | One-line Note |
|---|---|---|
| CTS | Common Type System | Defines all data types for interoperability |
| MSIL | Microsoft Intermediate Language | Platform-independent code generated by compiler |
| JIT | Just-In-Time Compiler | Converts MSIL to native code at runtime |
| Assembly | — | Deployment unit with MSIL, metadata & manifest |
Active Recall Questions
- What problems did .NET solve that COM/DCOM had?
- Explain the role of CLR with any 4 features.
- Differentiate between CTS and CLS.
- Why are .NET assemblies called self-describing?
- What is the difference between .NET Framework and .NET Core?
VB.NET Exam Notes
1. Components of VB.NET Development Environment
Key Components
| Component | Description |
|---|---|
| Visual Studio IDE | Main development environment with code editor, designer, and debugger |
| Toolbox | Contains controls (Button, TextBox, Label, etc.) |
| Solution Explorer | Shows all files, forms, and projects in the solution |
| Properties Window | Used to set properties of controls and forms |
| Code Editor | Where you write VB.NET code (supports IntelliSense) |
| Form Designer | Visual designer to design Windows Forms |
| Debugging Tools | Breakpoints, Watch window, Immediate window, Error List |
2-Mark Answer: The VB.NET development environment includes Visual Studio IDE, Toolbox, Solution Explorer, Properties Window, and Code Editor for designing and coding applications.
2. Variable Declaration in VB.NET
Implicit Declaration
- Variables can be declared without specifying a data type.
- Default data type becomes
Object. - Not recommended as it reduces performance and increases errors.
Dim name ' Implicit (treated as Object)
Explicit Declaration
- Recommended method. Data type is clearly specified.
- Uses
Askeyword.
Dim name As String
Dim age As Integer
Dim salary As Decimal
Option Explicit
- Forces explicit declaration of all variables.
- Added at the top of the code module:
Option Explicit On
- If
Option Explicit Off, implicit declaration is allowed (not recommended). - Exam Tip: Always keep
Option Explicit Onto avoid runtime errors.
3. Variable Scope in VB.NET
| Scope | Declared Inside | Accessible In | Lifetime |
|---|---|---|---|
| Local | Procedure / Function | Only within that procedure | Until procedure ends |
| Module-level | Module / Form | All procedures in that module | Until application ends |
| Global/Public | Module with Public |
Entire application | Until application ends |
Examples:
Public total As Integer ' Global scope
Dim counter As Integer ' Module-level scope
Private Sub Button1_Click(...)
Dim i As Integer ' Local scope
End Sub
4. Events in VB.NET
What are Events?
Events are actions triggered by the user or system (e.g., clicking a button, loading a form).
Adding an Event
- Go to Form Designer
- Double-click the control (e.g., Button) → Automatically creates the event
- Or use the Properties Window → Click the lightning icon (Events) → Double-click the desired event
Writing Event Code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show("Button Clicked!")
End Sub
Common Events
| Control | Common Event | Purpose |
|---|---|---|
| Button | Click | When button is clicked |
| Form | Load | When form is loaded |
| TextBox | TextChanged | When text is modified |
| ComboBox | SelectedIndexChanged | When selection changes |
2-Mark Answer:
An event is an action performed on a control. Code is written inside event procedures like Button1_Click. Events can be added by double-clicking the control or through the Properties window.
Quick Revision Points
- Use
Option Explicit Onfor safe coding - Prefer explicit declaration over implicit
- Variable scope decides where the variable can be accessed
- Events are handled using procedures ending with
Handles
Active Recall Questions
- What is the difference between implicit and explicit variable declaration?
- Why should we use
Option Explicit On? - Explain variable scope with examples.
- How do you add and write code for an event in VB.NET?
ASP.NET
1. Difference Between ASP and ASP.NET
| Feature | ASP (Classic ASP) | ASP.NET |
|---|---|---|
| Platform | Server-side scripting language | Framework for building web apps |
| Syntax | VBScript, JavaScript | C#, VB.NET, F# |
| State Management | Session & Application objects | ViewState, Session, Cache |
| Performance | Lower, interpreted code | Higher, pre-compiled code |
| Development Model | Procedural | Event-driven, component-based |
| Security | Limited built-in features | Stronger security features and controls |
| Ease of Use | More on raw HTML and scripts | Use of server controls, data binding |
| Support for MVC | Not supported | Full support for MVC architecture |
2-Mark Answer: ASP is a server-side scripting language that uses VBScript/JavaScript, while ASP.NET is a framework that uses compiled languages like C# and VB.NET, providing better performance, state management, and architecture.
2. Validation Controls in ASP.NET
Purpose
Validation controls are used to ensure user input is valid before processing it on the server side. They enhance user experience by providing immediate feedback.
Types of Validation Controls
| Control Type | Description |
|---|---|
| RequiredFieldValidator | Ensures a field is not empty |
| RangeValidator | Validates that a value is within a specified range |
| RegularExpressionValidator | Validates input based on a regex pattern |
| CompareValidator | Compares values of two controls |
| CustomValidator | Allows custom validation logic defined by user |
| ValidationSummary | Displays a summary of all validation errors |
Example
3. Methods to Deploy ASP.NET Solutions
Deployment Options
- Web Deployment Project
- Compiles the entire application into a single deployable unit.
- Beneficial for larger applications requiring optimized performance.
- File System Deployment
- Copy application files to a web server manually or using FTP.
- Suitable for simple applications or quick deployments.
- Web Publishing Wizard
- Provides a guided wizard to publish applications via File System or FTP.
- Good for fresh deployments without intricate build processes.
- Using Visual Studio
- Directly publish to Azure or web servers using Visual Studio's Publish Tool.
- Makes deployment process streamlined within the IDE.
- Containerization (Docker)
- Package the application in a Docker container for consistent deployment.
- Useful for microservices or cloud-based solutions.
2-Mark Answer: ASP.NET solutions can be deployed using Web Deployment Projects, File System deployments, Web Publishing Wizard, Visual Studio, or Docker containers.
4. Using Objects and Cookies in ASP.NET
Object Uses in ASP.NET
- Session State: Stores user-specific data throughout their session.
- Application State: Stores application-wide data.
- ViewState: Maintains state of server controls across postbacks.
- Cache: Allows temporary storage of frequently accessed data for improved performance.
Working with Cookies
What are Cookies?
- Small pieces of data stored on the client-side by the web browser.
How to Use Cookies in ASP.NET
' Setting a Cookie
Dim userCookie As HttpCookie = New HttpCookie("UserInfo")
userCookie("Username") = "JohnDoe"
userCookie.Expires = DateTime.Now.AddDays(1) ' Cookie expires in 1 day
Response.Cookies.Add(userCookie)
' Retrieving a Cookie
If Request.Cookies("UserInfo") IsNot Nothing Then
Dim username As String = Request.Cookies("UserInfo")("Username")
Response.Write("Welcome back, " & username)
End If
2-Mark Answer:
Cookies are small data stored on the client-side, useful for tracking user information. In ASP.NET, you can create, retrieve, and manage cookies through HttpCookie class.
Quick Revision Points
- ASP.NET provides a robust validation control system for user input.
- Different deployment methods can fit various project requirements, ranging from manual setups to modern DevOps practices.
- Objects like Session and Application State aid in managing user data and states effectively.
Active Recall Questions
- What are the main differences between ASP and ASP.NET?
- Name and describe various ASP.NET validation controls.
- What are the different methods to deploy ASP.NET solutions?
- Explain how to use cookies in ASP.NET and provide an example.
1. ADO.NET Architecture
ADO.NET is a set of classes in the .NET Framework that enables communication between .NET applications and data sources, such as databases and XML files. The architecture can be broken down into several components:
Architecture Overview
- Data Provider: Responsible for connecting to the data source, executing commands, and retrieving results.
- Examples: SQL Server Data Provider, OLE DB Provider, Oracle Data Provider.
- DataSet: An in-memory representation of data that can hold multiple tables, with relationships among them.
- DataAdapter: Acts as a bridge between a DataSet and a data source, facilitating data retrieval and updates.
- DataReader: A forward-only, read-only cursor for retrieving data from a database efficiently.
Diagram Overview
[Application] → [Data Provider] → [DataSet]
↓
[Data Adapter]
Key Benefits:
- Disconnected architecture: Allows applications to work with data offline.
- Supports different data sources and provides a uniform programming model.
2. Uses of Class Provider
Class providers in ADO.NET are specialized classes that connect to specific types of data sources. They encapsulate details about how to communicate with the data source.
Examples of Class Providers
- SqlClient: Used for SQL Server database connections.
- OleDb: Used for accessing data from any data source that supports OLE DB.
- OracleClient: For connecting to Oracle databases.
Uses:
- Connection Management: Handle secure connections to databases.
- Command Execution: Send SQL commands or stored procedures to the data source.
- Data Retrieval: Use the ExecuteReader or ExecuteScalar methods to fetch data.
3. DataReader
Overview
The DataReader provides a fast and efficient way to read data from a database in a forward-only manner. It is designed for scenarios where speed and performance are crucial.
Key Features
- Forward-Only: Data can only be read in the forward direction.
- Read-Only: Does not allow modification of data.
- Lightweight: Consumes less memory as it maintains an open connection to the data source.
Usage Example
Dim conn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("SELECT * FROM Employees", conn)
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader("Name"))
End While
reader.Close()
conn.Close()
4. DataAdapter
Overview
The DataAdapter serves as a bridge between a DataSet and a data source, populating the DataSet with data and managing changes made to it.
Key Functions
- Fill: Populates a DataSet with data from the database.
- Update: Saves changes made in the DataSet back to the database.
Usage Example
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
Dim ds As New DataSet()
adapter.Fill(ds, "Employees") ' Fills DataSet with data
adapter.Update(ds, "Employees") ' Updates database with changes
5. DataSet
Overview
A DataSet is an in-memory representation of data that can hold multiple data tables and relationships. It is disconnected from the data source.
Key Features
- Multiple Tables: Can store multiple tables and maintain relationships.
- Data Relations: Define relationships between tables using DataRelation objects.
- Data Binding: Easily bind to UI controls for display purposes.
Usage Example
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
adapter.Fill(ds, "Employees") ' Fills DataSet
6. Data Manipulation
CRUD Operations
ADO.NET provides a set of methods for performing Create, Read, Update, and Delete (CRUD) operations on the data:
- Create: Inserting new records into a database using INSERT statements.
- Read: Retrieving records through SELECT statements or using DataReaders and DataSets.
- Update: Modifying existing records in a database using UPDATE statements.
- Delete: Removing records using DELETE statements.
Example for Update Operation
Dim cmd As New SqlCommand("UPDATE Employees SET Salary = @Salary WHERE Id = @Id", conn)
cmd.Parameters.AddWithValue("@Salary", newSalary)
cmd.Parameters.AddWithValue("@Id", employeeId)
conn.Open()
cmd.ExecuteNonQuery() ' Executes the update command
conn.Close()
7. Data Navigation
Navigation within DataGridViews
The DataGridView control provides a powerful interface to display and navigate through data.
- Binding: Use the DataSource property to bind a DataSet or DataTable to a DataGridView.
- Navigation: Users can navigate through rows and columns, as well as edit data directly within the grid.
Example
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
Dim ds As New DataSet()
adapter.Fill(ds, "Employees")
dataGridView1.DataSource = ds.Tables("Employees") ' Bind DataSet to DataGridView
8. DataGridView Control
Overview
DataGridView is a control that displays data in a tabular format, allowing users to view and interact with data easily.
Features
- Editing: Enable users to edit rows directly.
- Sorting: Automatically sorts based on column header clicks.
- Paging**: Supports pagination for large datasets.
Usage Example
The following example shows how to configure a DataGridView for displaying data:
' Assuming dataGridView1 is your DataGridView control
dataGridView1.AutoGenerateColumns = True
dataGridView1.ReadOnly = False
dataGridView1.AllowUserToAddRows = False ' Disable adding new rows
Conclusion
ADO.NET provides a robust framework for working with data in .NET applications, enabling efficient data retrieval, manipulation, and navigation. Understanding its architecture and components is essential for creating data-driven applications.
Active Recall Questions
- What are the main components of ADO.NET architecture?
- Describe the functions of DataReader and DataAdapter in ADO.NET.
- How does a DataSet differ from a DataReader?
- Explain the CRUD operations in ADO.NET with examples.
- What features does the DataGridView control provide?
ADO.NET Exam Notes
1. ADO.NET Architecture
ADO.NET is a data access technology that provides a bridge between the front-end applications and back-end databases. Its architecture consists of the following components:
Key Components
-
Data Provider: Acts as a bridge between the application and the database. It is responsible for managing the connection, executing commands, and retrieving results.
-
Examples:
-
SqlClient(for SQL Server) -
OleDb(for any data source that supports OLE DB) -
OracleClient(for Oracle databases) -
DataSet: An in-memory representation of data that can hold multiple tables and relationships. It allows for disconnected data.
-
DataAdapter: Interacts between the DataSet and the database. It uses commands to populate the DataSet and update the database.
-
DataReader: Provides a way to read data from the database in a forward-only, read-only manner. It is efficient for retrieving data.
Architecture Diagram
[Application]
↓
[Data Provider] → [DataSet]
↓
[Data Adapter]
Key Benefits:
- Supports both connected and disconnected data access.
- Can work with various data sources using different data providers.
2. Uses of Class Provider
Class providers in ADO.NET are specialized classes responsible for connecting to specific databases and executing commands.
Common Class Providers
- SqlClient: Used for SQL Server.
- OleDb: Used for data sources that support OLE DB.
- OracleClient: For Oracle databases.
Functions of Class Providers
- Connection Management: Establish and manage connections to the database.
- Command Execution: Execute SQL commands and stored procedures.
- Data Retrieval: Use methods like
ExecuteReader()andExecuteScalar()to fetch data from the database.
3. DataReader
Overview
The DataReader is a lightweight, fast way to read data from a data source. It is designed for scenarios where fast, read-only access is essential.
Characteristics
- Forward-Only: Data can only be read in one direction.
- Read-Only: Does not allow updates to data.
- Memory Efficient: Requires less memory compared to DataSet as it maintains an open connection.
Example Usage
Dim conn As New SqlConnection(connectionString)
Dim cmd As New SqlCommand("SELECT * FROM Employees", conn)
conn.Open()
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read()
Console.WriteLine(reader("Name")) ' Access data by column name
End While
reader.Close()
conn.Close()
4. DataAdapter
Overview
The DataAdapter acts as a bridge between a DataSet and a data source for retrieving and saving data.
Functions
- Fill(): Populates a
DataSetwith data from the database. - Update(): Saves changes made to the
DataSetback to the database.
Example Usage
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
Dim ds As New DataSet()
adapter.Fill(ds, "Employees") ' Fills DataSet
adapter.Update(ds, "Employees") ' Updates database with changes
5. DataSet
Overview
A DataSet is an in-memory representation of data that can contain multiple tables, their relationships, and can be used in a disconnected mode.
Key Features
- Multiple Tables: Can hold multiple tables and define relationships between them.
- Data Relations: Establishes relationships using
DataRelationobjects. - Data Binding: Easily bind a
DataSetto UI controls for display.
Example Usage
Dim ds As New DataSet()
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
adapter.Fill(ds, "Employees") ' Fills DataSet with employee data
Dim table As DataTable = ds.Tables("Employees")
' Access table data here
6. Data Manipulation
ADO.NET allows performing CRUD (Create, Read, Update, Delete) operations easily.
CRUD Operations
- Create: Insert new records using the INSERT command.
- Read: Retrieve records using SELECT statements.
- Update: Modify existing records with UPDATE commands.
- Delete: Remove records with DELETE commands.
Example for Update Operation
Dim cmd As New SqlCommand("UPDATE Employees SET Salary = @Salary WHERE Id = @Id", conn)
cmd.Parameters.AddWithValue("@Salary", newSalary)
cmd.Parameters.AddWithValue("@Id", employeeId)
conn.Open()
cmd.ExecuteNonQuery() ' Executes the update command
conn.Close()
7. Data Navigation
Data Navigation with DataGridView
The DataGridView control is an essential component for displaying data in a tabular format.
Features
- Binding: Bind a
DataSetorDataTableto the DataGridView. - Navigation Features: Enables moving through rows and editing data directly in the grid.
Example Binding to DataGridView
Dim adapter As New SqlDataAdapter("SELECT * FROM Employees", conn)
Dim ds As New DataSet()
adapter.Fill(ds, "Employees")
dataGridView1.DataSource = ds.Tables("Employees") ' Bind DataSet to DataGridView
8. DataGridView Control
Overview
The DataGridView control is a sophisticated grid for displaying and editing tabular data.
Key Features
- In-place Editing: Users can edit data directly in the grid.
- Sorting: Automatically sorts data based on column headers.
- Customizable**: Highly customizable appearance and behavior.
Example Configuration
dataGridView1.AutoGenerateColumns = True
dataGridView1.ReadOnly = False
dataGridView1.AllowUserToAddRows = False ' Disable adding new rows
Conclusion
ADO.NET provides a robust and efficient way to interact with various data sources in .NET applications. Understanding its architecture and components is vital for creating effective data-driven applications.
Active Recall Questions
- What are the main components of ADO.NET architecture?
- Describe the functions and differences between DataReader and DataAdapter.
- How does a DataSet differ from a DataReader?
- Explain CRUD operations in ADO.NET with relevant examples.
- What features does the DataGridView control provide?