Unit - IV ( English Version )
Object Serialization and Remoting
Serialization and remoting in .NET allow objects to be stored, transmitted, and reconstructed in different environments. Serialization converts an object into a format that can be saved or transmitted, while remoting enables communication between applications.
System.IO Namespace
The System.IO namespace provides types for reading, writing, and managing data streams and files.
Streams:
A Stream is an abstract class used to transfer data.
Common streams:
FileStream
: Reads and writes data to files.MemoryStream
: Stores data in memory.NetworkStream
: Communicates over a network.
TextWriter and TextReader:
TextWriter: Writes text data to a stream (e.g.,
StreamWriter
).TextReader: Reads text data from a stream (e.g.,
StreamReader
).
BinaryWriter and BinaryReader:
BinaryWriter: Writes data in binary format to a stream.
BinaryReader: Reads binary data from a stream.
Example of Binary Read/Write:
Serialized Object Persistence and Formatters
Serialization converts an object into a byte stream for storage or transmission, and deserialization reconstructs the object from the byte stream.
Types of Serialization:
Binary Serialization: Uses
BinaryFormatter
for compact, efficient storage.XML Serialization: Converts objects into XML format using
XmlSerializer
.JSON Serialization: Converts objects into JSON using
JsonSerializer
.
BinaryFormatter Example:
Remoting
Remoting enables communication between different application domains, processes, or machines.
Remoting Basics:
Uses objects like
MarshalByRefObject
to pass data between applications.Communication can be achieved using channels like TCP or HTTP.
Remoting Configuration:
Server-Side: Host an object in a remoting service.
Client-Side: Consume the object from the server.
ADO.NET
ADO.NET is the data access technology used to connect, retrieve, manipulate, and update data in databases. It supports both connected and disconnected scenarios.
Connected and Disconnected Scenarios
Connected Scenario:
Requires an active connection to the database for performing operations.
Uses objects like
SqlConnection
,SqlCommand
, andSqlDataReader
.
Disconnected Scenario:
Works with data stored locally in a DataSet.
Allows changes to be made offline and updated later.
Key ADO.NET Objects
SqlConnection: Represents a connection to a database.
SqlCommand: Represents a query or command executed on the database.
SqlDataReader: Reads data row by row from a database.
DataSet: An in-memory representation of data.
SqlDataAdapter: Acts as a bridge between the database and the
DataSet
.
C# Windows Forms for Data Control
Windows Forms provides various controls for displaying and managing data.
Key Controls for Data Control
GridView:
Displays data in a tabular format.
Data can be bound to a
DataSource
.
DataSource:
Acts as a source of data for controls like
GridView
.
DataBinding:
Links UI controls to data sources.
Example:
ADO.NET in Windows Forms
Connect controls like
GridView
to aDataSet
orDataTable
.Example:
Summary
Object Serialization converts objects into a format for storage or transmission, using formatters like BinaryFormatter or JsonSerializer.
Remoting enables applications to communicate across processes or networks.
ADO.NET provides a robust way to connect to and manipulate databases, supporting both connected (
SqlCommand
,SqlDataReader
) and disconnected (DataSet
,SqlDataAdapter
) operations.C# Windows Forms allows data to be displayed and managed in a user-friendly interface using controls like
GridView
and databinding mechanisms.
Last updated