Sub kysimine1() Dim cn As New ADODB.Connection Dim rs As ADODB.Recordset Dim lause As String cn.Open "yhendus1" lause = "SELECT eesnimi FROM inimesed " & _ "ORDER BY eesnimi DESC" Set rs = cn.Execute(lause) Do While Not rs.EOF MsgBox rs("eesnimi") rs.MoveNext Loop cn.Close End Sub 'Kopeerige andmebaasis olevad eesnimed 'Exceli tabelisse Sub kopeerimine1() Dim cn As New ADODB.Connection Dim rs As ADODB.Recordset Dim lause As String cn.Open "yhendus1" lause = "SELECT eesnimi, perekonnanimi, mid(eesnimi, 1, 1) FROM inimesed " & _ "ORDER BY eesnimi DESC" Set rs = cn.Execute(lause) Cells.Clear reanr = 1 Do While Not rs.EOF 'MsgBox rs("eesnimi") Cells(reanr, 1) = rs("eesnimi") Cells(reanr, 2) = rs("perekonnanimi") Cells(reanr, 3) = rs(2) rs.MoveNext reanr = reanr + 1 Loop cn.Close End Sub Sub nimekatse() eesnimi = "maTi" tulemus = UCase(Mid(eesnimi, 1, 1)) & LCase(Mid(eesnimi, 2)) MsgBox tulemus End Sub Sub lisamine1() Dim cn As New Connection Dim lause As String cn.Open "yhendus1" lause = "INSERT INTO inimesed (eesnimi, perekonnanimi) " & _ "VALUES ('Siim', 'Tamm')" cn.Execute lause cn.Close End Sub 'ei tööta Sub lisamine2() Dim cn As New Connection Dim cm As New Command Dim lause As String cn.Open "yhendus1" lause = "INSERT INTO inimesed (eesnimi, perekonnanimi) " & _ "VALUES (?, ?)" Set cm.ActiveConnection = cn cm.CommandText = lause cm.Parameters.Append cm.CreateParameter("eesnimi", adVarChar) cm.Parameters.Append cm.CreateParameter("perekonnanimi", adVarChar) cm.Parameters("eesnimi").Value = "Leena" cm.Parameters("perekonnanimi").Value = "Ivask" cm.Execute cn.Close End Sub Sub lisamine3() Dim cn As New Connection Dim cm As New Command Dim lause As String cn.Open "yhendus1" uenimi = InputBox("Palun eesnimi") upnimi = InputBox("Palun perekonnanimi") lause = "INSERT INTO inimesed (eesnimi, perekonnanimi) " & _ "VALUES ('" & uenimi & "', '" & upnimi & "')" MsgBox lause cn.Execute lause cn.Close End Sub ' Lisage Exceli tabelist nimed andmebaasi Sub lisamine4() Dim cn As New Connection Dim rs As Recordset Dim lause As String cn.Open "yhendus1" reanr = 1 Do While Len(Cells(reanr, 6)) > 0 uenimi = Cells(reanr, 6) upnimi = Cells(reanr, 7) lause = "SELECT count(*) as kogus FROM inimesed " & _ "WHERE eesnimi='" & _ uenimi & "' AND perekonnanimi='" & upnimi & "'" MsgBox lause Set rs = cn.Execute(lause) If rs("kogus") = 0 Then lause = "INSERT INTO inimesed (eesnimi, perekonnanimi) " & _ "VALUES ('" & uenimi & "', '" & upnimi & "')" cn.Execute lause End If reanr = reanr + 1 Loop cn.Close End Sub