Home   MosaicPresentation format
<http://cnfolio.com/VBNetNotes40>
Visual Basic .NET

Introduction to ADO.NET





ADO.NET within the .NET Framework


Web ServicesWeb FormsWindows 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.

ADO.NET provider model

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.

New ADO.NET disconnected mode




Key ADO.NET namespaces






ADO.NET example


  1. Imports System.Data.OleDb
  2.  
  3. Module Example
  4.  
  5.     Public ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  6.                    "Data Source=C:\rolodex.xls;" & _
  7.                    "Extended Properties=""Excel 8.0;HDR=YES"""
  8.     Public ReadSQLString As String = "Select * From [RolodexSheet$]"
  9.     Public LocalDataTable As String = "Rolodex"
  10.  
  11.     Sub Main()
  12.         Use_Data_Reader()
  13.         Use_Data_Adapter()
  14.     End Sub
  15.  
  16.     Public Sub Use_Data_Reader()
  17.         Dim conn As New System.Data.OleDb.OleDbConnection(ConnectionString)
  18.         conn.Open()
  19.  
  20.         Dim cmd As New System.Data.OleDb.OleDbCommand(ReadSQLString, conn)
  21.         Dim reader As OleDbDataReader = cmd.ExecuteReader
  22.  
  23.         Do While reader.Read()
  24.             System.Console.Write(reader.GetString(0))
  25.             System.Console.WriteLine()
  26.         Loop
  27.  
  28.         reader.Close()
  29.         conn.Close()
  30.     End Sub
  31.  
  32.     Public Sub Use_Data_Adapter()
  33.         Dim conn As New System.Data.OleDb.OleDbConnection(ConnectionString)
  34.         conn.Open()
  35.  
  36.         Dim cmd As New System.Data.OleDb.OleDbCommand(ReadSQLString, conn)
  37.         Dim adapter As New OleDbDataAdapter(cmd)
  38.         Dim ds As New DataSet()
  39.         adapter.Fill(ds, LocalDataTable)
  40.         conn.Close()
  41.  
  42.         Dim row As DataRow
  43.         For Each row In ds.Tables(LocalDataTable).Rows
  44.             System.Console.Write(row(0))
  45.             System.Console.WriteLine()
  46.         Next
  47.     End Sub
  48.  
  49. End Module





Key steps when using ADO.NET


  1. Collect information about target database.
  2. Select and obtain appropriate data provider classes.
  3. Design solution using connected or disconnected modes.
  4. Develop solution.
  5. Analyse SQL security and performance.