Dim col As Integer, num As Integer
Dim v(1 To 10) As String
Dim r As Integer
Dim conn As Connection
Dim rs As Recordset
Public sql As String
Sub init()
With Frmlibri.DataGrid1
.AllowAddNew = False
.AllowDelete = False
.AllowUpdate = False
End With
End Sub
Sub query(str As String)
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.Provider = "microsoft.jet.oledb.4.0"
cn.ConnectionString = "c:\libri\libri.mdb"
cn.Open
rs.LockType = adLockOptimistic
rs.CursorLocation = adUseClient
rs.Source = str
Set rs.ActiveConnection = cn
rs.Open
If rs.EOF Then
MsgBox "Nessun record trovato", vbInformation, "Ricerca fallita"
Exit Sub
End If
Set Frmlibri.DataGrid1.DataSource = rs
End Sub
Private Sub DataGrid1_AfterInsert()
DataGrid1.BackColor = vbGreen
End Sub
Private Sub DataGrid1_OnAddNew()
DataGrid1.BackColor = vbYellow
End Sub
Private Sub mnuall_Click()
sql = "select * from libri;"
Call query(sql)
Call init
End Sub
Private Sub mnuaut_Click()
stringa = InputBox("inserisci autore", "Inserisci autore")
If stringa = "" Then
MsgBox "Input errato!", vbInformation, "Input errato"
Exit Sub
End If
sql = "select * from libri where autore='" & stringa & "';"
Call query(sql)
Call init
End Sub
Private Sub mnugen_Click()
stringa = InputBox("inserisci genere", "Inserisci genere")
If stringa = "" Then
MsgBox "Input errato!", vbInformation, "Input errato"
Exit Sub
End If
sql = "select * from libri where genere='" & stringa & "';"
Call query(sql)
Call init
End Sub
Private Sub mnuop_Click()
With Frmlibri.DataGrid1
.AllowAddNew = True
.AllowDelete = True
.AllowUpdate = True
End With
sql = "select * from libri;"
Call query(sql)
End Sub
Private Sub mnutit_Click()
stringa = InputBox("inserisci titolo libro", "Inserisci titolo libro")
If stringa = "" Then
MsgBox "Input errato!", vbInformation, "Input errato"
Exit Sub
End If
sql = "select * from libri where titolo='" & stringa & "';"
Call query(sql)
Call init
End Sub
Private Sub mnutot_Click()
sql = "select count(idlibro)as Totale_libri from libri;"
Call query(sql)
Call init
End Sub