Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class Form1
Dim provider As String
Dim dataFile As String
Dim connString As String
Public conn As OleDbConnection = New OleDbConnection
Public dr As OleDbDataReader
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles MyBase.Load
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\VB-workspace\WindowsApplication3\Access\Inventory.accdb"
connString = provider & dataFile
conn.ConnectionString = connString
End Sub
Private Sub FindButton_Click( sender As Object, e As EventArgs ) Handles FindButton.Click
conn.Open( )
DescriptionText.Clear( )
CostText.Clear( )
PriceText.Clear( )
Dim str As String
str = "SELECT * FROM Grocery WHERE (ID = " & IDText.Text & ")"
Dim cmd As OleDbCommand = New OleDbCommand( str, conn )
dr = cmd.ExecuteReader
While dr.Read( )
DescriptionText.Text = dr("Description").ToString
CostText.Text = dr("Cost").ToString
PriceText.Text = dr("Price").ToString
End While
conn.Close( )
End Sub
End Class
|