- Select Query – selects a group of records from one or more tables and displays the result in a datasheet where you can update records.
- Cross-tab Query – group data into categories and displays values in a compact, spreadsheet-like format with summary totals.
- Parameter Query – a query that when run displays a dialog box prompting you for information such as criteria for retrieving records or a value.
- Action Query – makes changes to many records in just one operation. There are four types of action queries: make table, delete, append and update.
- SQL Query – query you create using an SQL statement.
Showing posts with label Programming NC IV. Show all posts
Showing posts with label Programming NC IV. Show all posts
0 Types of Queries
By Central Luzon Skills Training Institute on
Types of Queries
0 ADO - Delete
By Central Luzon Skills Training Institute on
Private Sub cmdDelete_Click()
On Error GoTo ERR_MAIN
Dim objRS As ADODB.Recordset
Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset
''1 CONNECT TO THE DATA SOURCE
If Me.chkOracle Then
objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=yti;" & _
"User ID=scott;Password=tiger;"
Else
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\JPI\11th Batch Training\dbMSAccess.mdb"
End If
objConn.Open
''2 OPEN RECORDSET
With objRS
.Open "SELECT * FROM EMP WHERE DEPTNO=40", objConn, adOpenKeyset, adLockOptimistic
''The Recordcount property is used to return the number of records in the recordset.
' If .RecordCount > 0 Then
''MoveFirst - Moves the cursor to the first record in the recordset
.MoveFirst
Do Until .EOF
''Set the new salary - To accept the changes
.Delete
''MoveNext - Moves the cursor to the next record in the recordset
.MoveNext
Loop
' End If
''Close the recordset
.Close
End With
objConn.Close
Exit Sub
ERR_MAIN:
MsgBox Err.Number & " : " & Err.Description
End Sub
Private Sub cmdCommit_Click()
objConn.CommitTrans
objConn.Close
End Sub
Private Sub cmdRollback_Click()
objConn.RollbackTrans
objConn.Close
End Sub0 ADO - Update
By Central Luzon Skills Training Institute on
Private Sub cmdUPDATE_Click()
On Error GoTo ERR_MAIN
Dim objRS As ADODB.Recordset
Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset
''1 CONNECT TO THE DATA SOURCE
If Me.chkOracle Then
objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=yti;" & _
"User ID=scott;Password=tiger;"
Else
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\JPI\11th Batch Training\dbMSAccess.mdb"
End If
objConn.Open
objConn.BeginTrans
''2 OPEN RECORDSET
With objRS
.Open "SELECT * FROM EMP WHERE DEPTNO=40", objConn, adOpenKeyset, adLockOptimistic
''The Recordcount property is used to return the number of records in the recordset.
' If .RecordCount > 0 Then
''MoveFirst - Moves the cursor to the first record in the recordset
.MoveFirst
Do Until .EOF
''Set the new salary - To accept the changes
.Update Array("SAL"), _
Array(.Fields("SAL").Value + 500)
''MoveNext - Moves the cursor to the next record in the recordset
.MoveNext
Loop
' End If
''Close the recordset
.Close
End With
' objConn.Close
Exit Sub
ERR_MAIN:
MsgBox Err.Number & " : " & Err.Description
End Sub0 ADO - Add
By Central Luzon Skills Training Institute on
Private Sub cmdADD_Click()
On Error GoTo ERR_MAIN
Dim objRS As ADODB.Recordset
Dim intI As Integer
Dim strFields
Dim strValues
Set objConn = New ADODB.Connection
Set objRS = New ADODB.Recordset
''1 CONNECT TO THE DATA SOURCE
If Me.chkOracle Then
objConn.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source=yti;" & _
"User ID=scott;Password=tiger;"
Else
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\JPI\11th Batch Training\dbMSAccess.mdb"
End If
objConn.Open
''2 OPEN RECORDSET
With objRS
.Open "EMP", objConn, adOpenKeyset, adLockOptimistic
For intI = 1 To 2
strFields = Array("EMPNO", "ENAME", "JOB", "MGR", "HIREDATE", "SAL", "COMM", "DEPTNO")
strValues = Array(9997 + intI, "EDMON" & CStr(intI), "ANALYST", 7566, #4/1/2002#, 1000 * intI, 500 * intI, 40)
''Tell Access that we want to be in "add" mode
.AddNew strFields, strValues
''To accept new record
.Update
Next
''Close the recordset
.Close
End With
objConn.Close
Exit Sub
ERR_MAIN:
MsgBox Err.Number & " : " & Err.Description
End Sub
