README.md

December 4, 2022 ยท View on GitHub

ado.net

Description

Gives a basic knowldge of ADO.NET

More Info

Submitted On
Bym.shihipar
LevelBeginner
User Rating3.8 (15 globes from 4 users)
CompatibilityVB.NET
CategoryDatabases
World.Net (C#, VB.net)
Archive File

Source Code

Option Strict Off
Option Explicit On
Imports System
Imports System.Data.OleDb
 sub whatever()
 Dim myconnection As New OleDbConnection()
 Dim myReader As OleDbDataReader
 Dim cmSQL As OleDbCommand
 Dim strSQL As String
 myconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ database.mdb;"
 ('or add the database in bin folder of the project and substitute with the following)
myconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;"
 Try
  strSQL = "SELECT * FROM tablename"
  cmSQL = New OleDbCommand(strSQL, myconnection)
  myconnection.Open()
  myReader = cmSQL.ExecuteReader()
  Do While myReader.Read()
  Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
  Loop
 Catch Exp As OleDbException
  MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oledb Error")
 Catch Exp As Exception
  MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
 End Try
 ' Close and Clean up objects
 myconnection.Close()
 cmSQL.Dispose()
 myconnection.Dispose()
 myReader.Close)
 end sub