ADO, ADO.NET
_ActiveX Data Objects (ADO) is an application
program interface from Microsoft that lets a programmer writing Windows applications get access
to a relational or non-relational database from both Microsoft
and other database providers.... ADO is an object-oriented programming interface. ADO is more general and can be used to access all sorts of different types of data, including web pages, spreadsheets, and other types of documents. It is also part of an overall data access strategy from Microsoft called Universal Data Access, which is designed to provide a consistent way of accessing data regardless of how the data are structured...ADO is not more use in VB.net. It is for VB6. The basic steps are required to access the database using ADO are:
ADO.NET: ADO.NET is a set of computer software components that programmers can use to access data and data services. It is a part of the base class library that is included with the Microsoft .NET Framework. It is commonly used by programmers to access and modify data stored in relational database systems, though it can also access data in non-relational sources. ....
ADO.NET provides two central components .NET Data Provider and DataSet.
- Creating a new connection
- Creating a record set to retrieve data
- open a connection
- do all the desire searching processing on the accessed data....
- commit the changes you made to the data by using update query...
- close the record set
- close the connection..
ADO.NET: ADO.NET is a set of computer software components that programmers can use to access data and data services. It is a part of the base class library that is included with the Microsoft .NET Framework. It is commonly used by programmers to access and modify data stored in relational database systems, though it can also access data in non-relational sources. ....
ADO.NET provides two central components .NET Data Provider and DataSet.
- Data provider : Data in datasource is retrieved using various components of data provider and provide data to application and update the changes back to datasource.Components of Data Provider are like connection, command, data adapter ,data reader..
- DATASET: It is an in-memory representation of data. It can be used with multiple and differing data sources such as XML file or stream, data local to application. The DataSet object offers a disconnected data source architecture. The Dataset can work with the data it contain, without knowing the source of the data coming from....Dataset contains the datarowcollection, datacolumnconnection etc......The Dataset contains the copy of the data we requested. The Dataset contains more than one Table at a time. We can set up Data Relations between these tables within the DataSet. The data set may comprise data for one or more members, corresponding to the number of rows.
Different Between ADO and ADO.Net
- ADO used connected data architecture , while ADO.net used disconnected data environment.
- ADO used OLE DB to access data and is COM-based, while ADO.net uses XML as the format for transmitting data to and from your database and web application.
- In ADO a single table is used to access the data during connection, while In ADO.Net A collection of tables is used to store data which is used in offline connection of database
- ADO uses Record set to access data while ADO.Net uses Data set to access the data
- Transfer the data between different types of application is faster in ADO.Net , than ADO....
- ADO uses many resources to manipulating data in database than ADO.Net...
Accessing data using server explorer...
Server Explorer/Database Explorer is the server management console for Visual Studio. Use this window to open data connections and to log on to servers and explore their system services.This helps you to access and retrieve data to a connected database .YOu can perform such function such as List database tables, views, stored procedures, and functions,.....
Creating connection OLEDB and SQLDB?
OLEDB : Ole DB is a mechanism that allows applications to connect to databases that support the Ole DB framework. This is a Windows technology. This technology allows application developers to write software that can target any database, making the code for database manipulation simpler and easier to implement
There are two ways to connect to an Access database:
1. Using design time tool
2. Coding
Using design tool : Establishing a connection to an Access database in Server Explorer allows you to easily create OleDbConnection, OleDbDataAdapter, and OleDbCommand objects by dragging data objects from Server Explorer onto forms or designers...TO create a new connection :
Connecting to an Access Database by using codes : Another easy way to connect to database and access the data .....You can perform a coding...
SQLDB:
There are two ways to connect to an Access database:
1. Using design time tool
Using Design tool: Establishing a connection to SQL Server in Server Explorer allows you to easily create SqlConnection, SqlDataAdapter, and SqlCommand objects by dragging data objects from Server Explorer onto forms or designers...
There are two ways to connect to an Access database:
1. Using design time tool
2. Coding
Using design tool : Establishing a connection to an Access database in Server Explorer allows you to easily create OleDbConnection, OleDbDataAdapter, and OleDbCommand objects by dragging data objects from Server Explorer onto forms or designers...TO create a new connection :
- In Server Explorer, right-click Data Connections and click Add Connection.
- On the advance tab click on the provider
- Click the Microsoft Jet 4.0 OLE DB Provider, then click ok..
- Now click on the browse button and select the database .MDB file (MS ACCESS FILE)
- Type the User ID to use for login
- Type the Password to use for authentication when you log on to the data source.
- click ok...
Connecting to an Access Database by using codes : Another easy way to connect to database and access the data .....You can perform a coding...
- create a form in VB .NET application
- Double click form
- "Imports System.Data.OleDb" outside the class of form...
- CLASS HIMANSHU
- DIM cn AS NEW OLEDB.OLEDBCONNECTION
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- 'we have successfully created a connection but the datasource and provider is not available till now ...To add provider using the following code.....
" cn.ConnectionString = ("provider=microsoft.jet.oledb.4.0; data source=I:\New Microsoft Office Access Application.mdb")" ....Here microsoft.jet.oledb.4.0 is the provider engine which is provided by the microsoft corporation and the full path is of our data source from where data source is beng accessed...
- END SUB
- END CLASS
SQLDB:
There are two ways to connect to an Access database:
1. Using design time tool
Using Design tool: Establishing a connection to SQL Server in Server Explorer allows you to easily create SqlConnection, SqlDataAdapter, and SqlCommand objects by dragging data objects from Server Explorer onto forms or designers...
- In Server Explorer, right-click Data Connections and click Add Connection.
- change data source to Microsoft SQL server compact 3.5 and click ok
- Now click on create database, give the name to you SQL database and select the path to save your Database..
- NOw enter the password ........
- Test you connection Using test connection button....
- you are successfully connected to SQL database...
- Connection is established , You will found a name of data base Created , in the server explorer..
- Double click to expand the database...
- Right click on table and select Add Table...
- it will Take you to a create table window...There you an enter you columns and give the size of the column...
- YOu are successful in adding table...
- Now you can use the SQL table anywhere in you form...
sql.jpg | |
File Size: | 25 kb |
File Type: | jpg |
Command, Dataadapter and data set?
Command & Data reader: The Command Object in ADO.NET executes SQL statements and Stored Procedures against the data source specified in the Connection Object. The Command Object required an instance of a Connection Object for executing the SQL statements. That is, for retrieving data or execute an SQL statement against a Data Source , you have to create a Connection Object and open a connection to the Data Source, and assign the open connection to the connection property of the Command Object. When the Command Object return result set , a Data Reader is used to retrieve the result set....
Public Sub INSERT()
Dim CMD As OleDbCommand
Dim DR As OleDbDataReader
cn.Open()
CMD= New OleDbCommand("insert into table1 values('" & TextBox1.Text & "', " & textbox2.Text& ")", cn)
DR = CMD.ExecuteReader
MessageBox.Show("RECORD INSERTED SUCCESSFULLY")
DR.Close()
cn.Close()
End Sub
Dataadapter: DataAdapter is a part of the ADO.NET Data Provider. DataAdapter provides the communication between the Dataset and the Datasource. We can use the DataAdapter in combination with the DataSet Object. That is these two objects combine to enable both data access and data manipulation capabilities... The DataAdapter can perform Select , Insert , Update and Delete SQL operations in the Data Source..It is also acts as a mediator between data source and data source....Data adapter insert all updation in to the database....It also uses an object connection provided by .Net framework to connect to data source...Every framework uses different data adapter to connect to different source point..For example we use OLEDB data adapter for OLEDB connection and SQLdataadapter for SQL Query connection...
Data table: The DataTable class is a member of the System.Data namespace within the .NET Framework class library. You can create and use a DataTable independently or as a member of a DataSet, and DataTable objects can also be used in conjunction with other .NET Framework objects, including the DataView. .....
Dataset : It is an in-memory representation of data. It can be used with multiple and differing data sources such as XML file or stream, data local to application. The DataSet object offers a disconnected data source architecture. The Dataset can work with the data it contain, without knowing the source of the data coming from....Dataset contains the datarowcollection, datacolumnconnection etc......The Dataset contains the copy of the data we requested. The Dataset contains more than one Table at a time. We can set up Data Relations between these tables within the DataSet. The data set may comprise data for one or more members, corresponding to the number of rows....
public sub show
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
cn.Open()
da = New OleDbDataAdapter("select *from Table1 ", cn)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
cn.Close()
end sub
Public Sub INSERT()
Dim CMD As OleDbCommand
Dim DR As OleDbDataReader
cn.Open()
CMD= New OleDbCommand("insert into table1 values('" & TextBox1.Text & "', " & textbox2.Text& ")", cn)
DR = CMD.ExecuteReader
MessageBox.Show("RECORD INSERTED SUCCESSFULLY")
DR.Close()
cn.Close()
End Sub
Dataadapter: DataAdapter is a part of the ADO.NET Data Provider. DataAdapter provides the communication between the Dataset and the Datasource. We can use the DataAdapter in combination with the DataSet Object. That is these two objects combine to enable both data access and data manipulation capabilities... The DataAdapter can perform Select , Insert , Update and Delete SQL operations in the Data Source..It is also acts as a mediator between data source and data source....Data adapter insert all updation in to the database....It also uses an object connection provided by .Net framework to connect to data source...Every framework uses different data adapter to connect to different source point..For example we use OLEDB data adapter for OLEDB connection and SQLdataadapter for SQL Query connection...
Data table: The DataTable class is a member of the System.Data namespace within the .NET Framework class library. You can create and use a DataTable independently or as a member of a DataSet, and DataTable objects can also be used in conjunction with other .NET Framework objects, including the DataView. .....
Dataset : It is an in-memory representation of data. It can be used with multiple and differing data sources such as XML file or stream, data local to application. The DataSet object offers a disconnected data source architecture. The Dataset can work with the data it contain, without knowing the source of the data coming from....Dataset contains the datarowcollection, datacolumnconnection etc......The Dataset contains the copy of the data we requested. The Dataset contains more than one Table at a time. We can set up Data Relations between these tables within the DataSet. The data set may comprise data for one or more members, corresponding to the number of rows....
public sub show
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter
cn.Open()
da = New OleDbDataAdapter("select *from Table1 ", cn)
da.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
cn.Close()
end sub
Display all data on grid view....
To view data on datagridview we must have to first to crate a connection with oledb then access the records from the database to view data on datagridview....
Using
public sub display()
Draw a output diagram.....
using Graphical view: Without coding we can also view the data on the data grid view ...But it is very easily to create a datagrid view with the help of graphical version...The main difference between command and GUI mode is that , if any updation is done in the database will show the effect in the datagridview which is done b using command base, it will never show the effect in the datagridview which is configured by using the graphical mode...To create a data source please perform this steps:
- create a form in VB .NET application
- double click form
- "Imports System.Data.OleDb" outside the class of form...
- "Dim cn As New OleDbConnection" ..This is used to create a connection to access the data source...
- we have successfully created a connection by the provider is not available till now ...To add provider using the following code....." cn.ConnectionString = ("provider=microsoft.jet.oledb.4.0; data source=I:\New Microsoft Office Access Application.mdb")" ....Here microsoft.het.oledb.4.0 is the provider and the full path is of our data source.....
Using
public sub display()
- Dim dt As New DataTable
- Dim ds As New DataSet
- ds.Tables.Add(dt)
- Dim da As New OleDbDataAdapter
- cn.Open()
- da = New OleDbDataAdapter("select *from Table1 ", cn)
- da.Fill(dt)
- DataGridView1.DataSource = dt.DefaultView ' This add all record in datagridview...
- cn.Close()
Draw a output diagram.....
using Graphical view: Without coding we can also view the data on the data grid view ...But it is very easily to create a datagrid view with the help of graphical version...The main difference between command and GUI mode is that , if any updation is done in the database will show the effect in the datagridview which is done b using command base, it will never show the effect in the datagridview which is configured by using the graphical mode...To create a data source please perform this steps:
- Create a New Windows Application Form....
- press CTrl + Alt + X to view the toolbox and then Drag and Drop DATAGRIDVIEW from toolbox...
- On the top right corner you will find a a small button like [>].....TO see its contain click on it...
- It will show a view as shown in figure....
- Now click choose datasource from that contents...And select ADD DATA SOURCE..
- It will take you to data source configuration wizard......SELECT DATABASE..and click next
- Now click on newconnection , Browse you database source file....and click OK...
- It will ask you to save the connecting as "DB1CONNECTIONSTRING" and Click Next...
- Now Time come to choose you Database Object....Check the "TABLES AND VIEWS"
- Click FINISH
- Now Run The YOUR PROJECT you will Find the Record of the Database in the DATAGRIDVIEW...
datagrid.jpg | |
File Size: | 18 kb |
File Type: | jpg |