0% found this document useful (0 votes)
5 views

data binding - unit 4

Data Binding in .NET allows visual elements to connect with data sources, enabling two-way data synchronization. It includes simple data binding for single data elements and complex data binding for multiple records, with specific steps for implementation. Assemblies in .NET are collections of types and resources that can be executable or library files, providing essential information for the common language runtime and can be managed as private or shared assemblies.

Uploaded by

hello4mjeba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

data binding - unit 4

Data Binding in .NET allows visual elements to connect with data sources, enabling two-way data synchronization. It includes simple data binding for single data elements and complex data binding for multiple records, with specific steps for implementation. Assemblies in .NET are collections of types and resources that can be executable or library files, providing essential information for the common language runtime and can be managed as private or shared assemblies.

Uploaded by

hello4mjeba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Binding – unit 4

DataBinding is a powerful feature provided by the .NET Framework that enables visual elements
such as TextBox, Datagrid, etc in a client to connect to a datasource such
as DataSets, DataViews, Arrays, 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.
Below is a graphical description of the concept of databinding:

The .NET Framework provides a very flexible and powerful approach to databinding and allows the
programmer to have a fine control over the steps involved in the whole process
Dataflow during DataBinding:

 A control can have many properties that can be bound.


 Each databound property of the control has an associated Binding object.
 All Binding objects for a control are contained by the
control's DataBindings property, which is an instance
of ControlBindingsCollection class.
 Each databinding object talks to
a CurrencyManager or PropertyManager object.
 CurrencyManager and PropertyManager are derived from
the BindingManagerBase class.
 The BindingContext object is a collection
of CurrencyManager and PropertyManager objects.
 By default, a form contains one BindingContext object.
More BindingManagerBase objects can be created and added to
the BindingContext collection.
 Each CurrencyManager or PropertyManager encapsulates the data access to
one datasource per BindingContext object.

Type of data binding


1. Simple data binding: The ability of a control to bind to a single data element, such as
a value in a column in a dataset table. Simple data binding is the type of binding typical for
controls such as a TextBox control or Label control, which are controls that typically only
display a single value. In fact, any property on a control can be bound to a field in a
database. There's extensive support for this feature in Visual Studio.
Steps:
1. Connect to a data source.
2. In Visual Studio, select the control on the form and then open
the Properties window.
3. Expand the DataBindings property, and then in the Advanced box,
select the ellipsis button ( ) to display the Formatting and
Advanced Binding dialog, which has a complete list of properties
for that control.
4. Select the property you want to bind, and then select
the Binding arrow.
A list of available data sources is displayed.
5. Expand the data source you want to bind the property to until you
find the single data element you want.
For example, if you're binding to a column value in a dataset's table,
expand the name of the dataset, and then expand the table name to
display column names.
6. Select the name of an element to bind to.
7. In the Format type box, select the format you want to apply to the
data displayed in the control.
The following table shows the format types and options.
Format type Formatting option
No No options.
Formatting
Numeric Specify number of decimal places by using Decimal places up-down control.
Currency Specify the number of decimal places by using Decimal places up-down control.
Date Time Choose how the date and time should be displayed by selecting one of the items in
the Type selection box.
Scientific Specify the number of decimal places by using Decimal places up-down control.
Custom Specify a custom format string.
8. Select OK to close the Formatting and Advanced Binding dialog
and return to the Properties window.
2. Complex data binding: The ability of a control to bind to more than one data
element, typically more than one record in a database. Complex binding is also called list-
based binding. Examples of controls that support complex binding are the DataGridView,
ListBox, and ComboBox controls.
Steps:
1. the DataSource property is set to a data source object. Possible data
sources include a BindingSource bound to data, a data table, a data
view, a dataset, a data view manager, an array, or any class that
implements the IList interface.
2. To bind a table, the DisplayMember property will be set to the name of
a column in the data source.
Unit 4- Assemblies in .NET
An assembly is a collection of types and resources that are built to work together and form a logical
unit of functionality. Assemblies take the form of executable (.exe) or dynamic link library (.dll) files,
and are the building blocks of .NET applications. They provide the common language runtime with
the information it needs to be aware of type implementations.
Assemblies have the following properties:
 Assemblies are implemented as .exe or .dll files.
 For libraries that target .NET Framework, you can share assemblies between
applications by putting them in the global assembly cache (GAC).
 Assemblies are only loaded into memory if they're required.. Therefore, assemblies
can be an efficient way to manage resources in larger projects.
 You can programmatically obtain information about an assembly by using reflection.
 You can load an assembly just to inspect it by using the MetadataLoadContext class on
.NET and .NET Framework. MetadataLoadContext replaces
the Assembly.ReflectionOnlyLoad methods.
Assemblies in the common language runtime
Assemblies provide the common language runtime with the information it needs to be
aware of type implementations. To the runtime, a type doesn't exist outside the context of
an assembly.
An assembly defines the following information:
 Code that the common language runtime executes. Each assembly can have only one
entry point: DllMain, WinMain, or Main.
 The security boundary. An assembly is the unit at which permissions are requested
and granted..
 The type boundary. Every type's identity includes the name of the assembly in which
it resides.
 The reference-scope boundary: The assembly manifest has metadata that's used for
resolving types and satisfying resource requests. The manifest specifies the types and
resources to expose outside the assembly and enumerates other assemblies on which
it depends. Common intermediate language (CIL) code in a portable executable (PE)
file won't be executed unless it has an associated assembly manifest.
 The version boundary. The assembly is the smallest versionable unit in the common
language runtime. All types and resources in the same assembly are versioned as a
unit
 The deployment unit: When an application starts, only the assemblies that the
application initially calls must be present. Other assemblies, such as assemblies
containing localization resources or utility classes, can be retrieved on demand.
Types:
 Static assemblies are stored on a disk in portable executable (PE) files. Static
assemblies can include interfaces, classes, and resources like bitmaps, JPEG files,
and other resource files.
 dynamic assemblies are run directly from memory and aren't saved to disk before
execution. It can be saved to disk after they've been executed.
 Private Assembly: It is accessible by a single application.
 Shared Assembly: It is accessible by multiple applications.
Create an assembly
There are several ways to create assemblies.
1.use development tools, such as Visual Studio that can create .dll or .exe files.
2.use tools in the Windows SDK to create assemblies with modules from other
development environments.
3. use common language runtime APIs, such as System.Reflection.Emit, to create dynamic
assemblies.
Compile assemblies by building them in Visual Studio, building them with .NET Core
command-line interface tools, or building .NET Framework assemblies with a command-line
compiler.
The following procedures show how to create single-file assemblies using command-line
compilers.
Create an assembly with an .exe extension
At the command prompt, type the following command:
<compiler command> <module name>
where, compiler command is the compiler command for the language used in code
module, and module name is the name of the code module to compile into the assembly.
The following example creates an assembly named myCode.exe from a code module
called myCode.
C#
csc myCode.cs
Create an assembly with an .exe extension and specify the output file name
At the command prompt, type the following command:
<compiler command> /out:<file name> <module name>
In this command, compiler command is the compiler command for the language used in
your code module, file name is the output file name, and module name is the name of the
code module to compile into the assembly.
The following example creates an assembly named myAssembly.exe from a code module
called myCode.
C#
csc -out:myAssembly.exe myCode.cs
Create library assemblies
A library assembly is similar to a class library. It contains types that will be referenced by
other assemblies, but it has no entry point to begin execution.
To create a library assembly, at the command prompt, type the following command:
<compiler command> -t:library <module name>
In this command, compiler command is the compiler command for the language used in
your code module, and module name is the name of the code module to compile into the
assembly. You can also use other compiler options, such as the -out: option.
The following example creates a library assembly named myCodeAssembly.dll from a code
module called myCode.
C#
csc -out:myCodeLibrary.dll -t:library myCode.cs

Managing .NET Assemblies


Assemblies can be private or shared: by default, most simple programs consist of a private
assembly because they are not intended to be used by other applications.
In order to share an assembly with other applications, it must be placed in the global
assembly cache (GAC).
To share an assembly:
1. Create your assembly.
2. Assign a strong name to your assembly.
3. Assign version information to your assembly.
4. Add your assembly to the global assembly cache.
5. Access the types contained in the assembly from other applications.

One mark: Satellite and Resource-only assemblies


Satellite assemblies are often used to deploy language-specific resources for an application

You might also like