32
Disconnected Architecture in VB.NET By: Ambreen Gillani

Disconnected Architecture and Crystal report in VB.NET

Embed Size (px)

Citation preview

Page 1: Disconnected Architecture and Crystal report in VB.NET

Disconnected Architecture in VB.NET

By:

Ambreen Gillani

Page 2: Disconnected Architecture and Crystal report in VB.NET

VB.NETDisconnected Architecture

Data Sets, Data Tables, Data Adapters, Stored

Procedures and managing their transections.

Page 3: Disconnected Architecture and Crystal report in VB.NET

Disconnected Architecture in ADO.NET

Page 4: Disconnected Architecture and Crystal report in VB.NET

ADO.NET

ADO.NET is part of the .NET framework technology that allows

you to access and modify data from different data sources.

It supports many types of data sources such as Microsoft SQL

Server, MySQL, Oracle, and Microsoft Access.

The .NET Framework provides a number of data providers that

you can use. These data providers are used to connect to a data

source, executes commands, and retrieve results.

Page 5: Disconnected Architecture and Crystal report in VB.NET

ADO.NET

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 Data

Set

ADO.net uses dataset object for disconnected architecture And

data adapter fills it.

Page 6: Disconnected Architecture and Crystal report in VB.NET

Data Set

Page 7: Disconnected Architecture and Crystal report in VB.NET

DataSet

The DataSet is the central component in the ADO.NET Disconnected Data Access Architecture.

A DataSet is an in-memory data store that can hold multiple tables at the same time.

DataSets only hold data and do not interact with a Data Source.

One of the key characteristics of the DataSet is that it has no knowledge of the underlying Data Source that might have been used to populate it.

DataSet is disconnected architecture gets all records at once and closes connection and are available even after connection is closed

A DataSet is made up of a collection of tables, relationships, and constraints

Page 8: Disconnected Architecture and Crystal report in VB.NET

DataSet

Syntax:

The Data Set is not connected directly to a Data Source through a

Connection object when you populate it. It is the Data Adapter that

manages connections between Data Source and Dataset by fill the data from Data Source to the Dataset and giving a disconnected

behavior to the Dataset.

The Data Set contains Data Tables. The Data Tables contains Data

Row and Data Columns. A Data Set or a Data Table can be used with

a Command and a Data Adapter object to store query results.

Page 9: Disconnected Architecture and Crystal report in VB.NET

. Program Example for DataSet:

Page 10: Disconnected Architecture and Crystal report in VB.NET

Data Adapter

Page 11: Disconnected Architecture and Crystal report in VB.NET

Data Adapter

The Data Adapter acts as a bridge between the Disconnected Objects

Data Adapter is a part of the ADO.NET Data Provider.

Data Adapter provides the communication between the Dataset and the Data source.

We can use the DataAdapter in combination with the DataSet Object.

The Data Adapter can perform Select , Insert , Update and Delete SQL operations in the Data Source.

DataAdapter - A DataAdapter object is used to fill a DataSet/DataTable with query results.

Syntax:

Dim adapter As New SqlDataAdapter

adapter.SelectCommand = New SqlCommand(sql, sqlCnn)

Dim ds As New DataSet

adapter.Fill(ds)

Page 12: Disconnected Architecture and Crystal report in VB.NET

Data Adapter

Adapter.Update(dataset_variable,”Table_Name”)

This command is used to update database after working on

dataset.

This can be thought of as the adapter between the

connected and disconnected data models.

A Command object will be used to execute the query and

a DataAdapter will use this Command object and fill the

query results coming from the database into

a DataSet/DataTable.

Page 13: Disconnected Architecture and Crystal report in VB.NET

How adapter fills dataset in disconnected

architecture

and how dataset is used further…..

Page 14: Disconnected Architecture and Crystal report in VB.NET

Data Table

Page 15: Disconnected Architecture and Crystal report in VB.NET

DataTables

The DataTable class is a member of the System.Data namespace within the

.NET Framework class library.

A database table commonly has a column or group of columns that uniquely identifies each row in the table. This identifying column or group of columns is

called the primary key.

Adding Primary Key For specific Table:

table1.PrimaryKey = New DataColumn()

table1.Columns(“RollNo")

Page 16: Disconnected Architecture and Crystal report in VB.NET

DataTables

Syntax:

Imports system.data

Dim dt as DataTable = new DataTable()

dt.TableName = “Records”

’or use the DataTable(string TableName) constructor

Dim dt DataTable = new DataTable(“Records”)

Page 17: Disconnected Architecture and Crystal report in VB.NET

DataTables

Adding A column to a Data Table:

dim dc as datacolumn = new datacolumn()

dc.columnName=“Names”

dc.datatype=GetType(String)

dc.defaultvalue=0

‘At the end

dt.column.add(dc)

(Dt is the datatable variable defined previousely)

Page 18: Disconnected Architecture and Crystal report in VB.NET

DataTables

Adding A row to a Data Table:

Page 19: Disconnected Architecture and Crystal report in VB.NET

DataTablesCreating A complete Data Table:' Create new DataTable instance.

Dim table As New DataTable

' Create three typed columns in the DataTable.

table.Columns.Add(“RollNo", GetType(Integer))

table.Columns.Add(“Name”, GetType(String))

table.Columns.Add(“Age", GetType(Integer))

' Add three rows with those columns filled in the DataTable.

table.Rows.Add(7756, “Ambreen Gillani", 20)

table.Rows.Add(7779, “Maira Abbas", 20)

table.Rows.Add(7764, "Hafiza Kawish Amin", 20)

Page 20: Disconnected Architecture and Crystal report in VB.NET

Insert, Update Delete Command in disconnected architecture

Page 21: Disconnected Architecture and Crystal report in VB.NET

Guidelines….

In disconnected architecture we work on dataset and that

dataset is filled by the data adapter.

First the connection Is opened and all the data is copied

from data source to dataset by the adapter and then the

connection Is closed.

Adapter.fill(ds) is used.

Then we perform operations on that dataset and after

working, adapter.update command is required to update

the changes made to the datasource.

Page 22: Disconnected Architecture and Crystal report in VB.NET

Insertion

Page 23: Disconnected Architecture and Crystal report in VB.NET

Updating:

Page 24: Disconnected Architecture and Crystal report in VB.NET

Deletion:

Page 25: Disconnected Architecture and Crystal report in VB.NET

Display Records in Disconnected

Architecture

Display records using DataSet:

Page 26: Disconnected Architecture and Crystal report in VB.NET

Searching In disconnected Architecture

Searching For a specific Record :

Page 27: Disconnected Architecture and Crystal report in VB.NET

Stored Procedure

Page 28: Disconnected Architecture and Crystal report in VB.NET

Stored Procedures:

A stored procedure is a precompiled executable object that contains one or more SQL statements.

Using stored procedures, database operations can be encapsulated in a single command, optimized for best performance, and enhanced with additional security.

To call a stored procedure from VB.NET application, set the CommandType of the Command object to Stored Procedure and command text to that name you specified to Stored Procedure.

Page 29: Disconnected Architecture and Crystal report in VB.NET

Complete code for Insert & Delete record using

Stored Procedures….

Page 30: Disconnected Architecture and Crystal report in VB.NET

Stored Procedure For Inserting & Deleting

Record:

Page 31: Disconnected Architecture and Crystal report in VB.NET

Create And Drop Table Code:

Page 32: Disconnected Architecture and Crystal report in VB.NET

Stored Procedures For Create and

drop: