Author : Catherine Poncio
Date Submitted : 9/3/2007
Category : Database
Compatibility : .NET,VB 6
This code has been accessed 8267 times.
Task : In this sample code you will know how to connect to the database using microsoft Jet Oledb 4.0.
Declarations
Code
Option Explicit
Dim txt As Control
Private Sub Command1_Click()
Dim db As New adodb.CONNECTION
Dim rs As New adodb.Recordset
Dim sql As String
Dim inptbx As String
inptbx = InputBox("Enter The First Name of the Student")
sql = "select * from tablenames where FirstName='" & inptbx & "'"
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\namedatabase.mdb"
db.Open
rs.Open sql, db, adOpenKeyset, adLockPessimistic, adCmdText
End Sub
Private Sub Command2_Click()
Dim dbs As New adodb.CONNECTION
Dim rss As New adodb.Recordset
dbs.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\namedatabase.mdb"
dbs.Open
rss.Open "select * from tablenames", dbs, adOpenKeyset, adLockPessimistic, adCmdText
With rss
.AddNew
.Fields!FirstName = Form1.txtFirstName
.Fields!LastName = Form1.txtLastName
.Fields!MiddleName = Form1.txtMiddleName
.Update
MsgBox "Saving", vbInformation
End With
End Sub
Private Sub Command3_Click()
For Each txt In Form1
If TypeOf txt Is TextBox Then
txt = ""
txtFirstName.SetFocus
End If
Next
End Sub
Private Sub Command4_Click()
Unload Me
End Sub