Visual Basic .NET
Introduction to ADO.NET
ADO.NET within the .NET Framework
| Web Services | Web Forms | Windows Forms |
Data and XML Classes ADO.NET, SQL, XML, XSLT, XPath, etc. |
Framework Base Classes io, string, net, security, threading, text, reflection, etc. |
Common Language Runtime exception, type checking, compiling, etc. |
| Microsoft Windows |
ADO.NET uses a provider model
This approach favors
optimized database connectivity and
custom vendor features.
Provider specific implementations are the
green boxes.
ADO.NET core interfaces are the
red names.
ADO.NET uses a disconnected mode
This mode provides
flexible data manipulation and
binding to graphical controls.
Key ADO.NET namespaces
- System.Data
- System.Data.DataSet
- System.Data.DataTable
- System.Data.DataColumn
- System.Data.DataRowCollection
- System.Data.DataRow
- System.Data.Common
- System.Data.OleDb
- System.Data.OleDb.OleDbConnection
- System.Data.OleDb.OleDbDataReader
- System.Data.OleDb.OleDbDataAdapter
- System.Data.OleDb.OleDbCommand
- System.Data.Oracle
- System.Data.SqlClient
ADO.NET example
Imports System.Data.OleDb
Module Example
Public ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\rolodex.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""
Public ReadSQLString As String = "Select * From [RolodexSheet$]"
Public LocalDataTable As String = "Rolodex"
Sub Main()
Use_Data_Reader()
Use_Data_Adapter()
End Sub
Public Sub Use_Data_Reader()
Dim conn As New System.Data.OleDb.OleDbConnection(ConnectionString)
conn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand(ReadSQLString, conn)
Dim reader As OleDbDataReader = cmd.ExecuteReader
Do While reader.Read()
System.Console.Write(reader.GetString(0))
System.Console.WriteLine()
Loop
reader.Close()
conn.Close()
End Sub
Public Sub Use_Data_Adapter()
Dim conn As New System.Data.OleDb.OleDbConnection(ConnectionString)
conn.Open()
Dim cmd As New System.Data.OleDb.OleDbCommand(ReadSQLString, conn)
Dim adapter As New OleDbDataAdapter(cmd)
Dim ds As New DataSet()
adapter.Fill(ds, LocalDataTable)
conn.Close()
Dim row As DataRow
For Each row In ds.Tables(LocalDataTable).Rows
System.Console.Write(row(0))
System.Console.WriteLine()
Next
End Sub
End Module
Key steps when using ADO.NET
- Collect information about target database.
- Select and obtain appropriate data provider classes.
- Design solution using connected or disconnected modes.
- Develop solution.
- Analyse SQL security and performance.