VB icon


Submitted on: 1/1/2015 6:03:00 PM
By: m.shihipar (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: VB.NET
Views: 1180
     Gives a basic knowldge of ADO.NET
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
// Name: ado.net
// Description:Gives a basic knowldge of ADO.NET
// By: m.shihipar (from psc cd)

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;"
strSQL = "SELECT * FROM tablename"
cmSQL = New OleDbCommand(strSQL, myconnection)
myReader = cmSQL.ExecuteReader()
Do While myReader.Read()
Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
 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
 end sub

Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.