Salve,
ho un progetto da fare,l'inizio di questo progetto dice che ho un database(mdb), che ha una tabella con una sola riga dove ci sono tre password(pass1,pass2,pass3),la pass1 può accedere a determinate funzioni,la pass2 ad altre e l'ultima ad altre.
questa pass viene digitata in una textbox, devo prelevare questa pass confrontarla tra le tre e prendere questo valore e fsrgli fare le proprie determinate funzioni.
io il codice l'ho fatto e funziona,però non sono convinto che sia il sistema migliore.
Il codice è questo:
Public Enum Livelli
master = 1
pluto
pippo
nonautenticato
End Enum
Public liv As Livelli
Public Function FindPassword(ByVal pass As String) As Livelli
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:miodatabase.mdb;"
Dim cn As New OleDbConnection(strConn)
Dim cm As New OleDbCommand()
Dim dt As OleDbDataReader
Dim da As New OleDbDataAdapter(cm)
cm.CommandText = "SELECT PSW1,PSW2,PSW3 FROM Anagrafica WHERE PSW1='" & pass & "'" & " OR PSW2 ='" & pass & "'" & " OR PSW3 =' " & pass & "' "
cm.Connection = cn
Try
cn.Open()
dt = cm.ExecuteReader()
If dt.Read() Then
If (pass = "master") Then
liv = CType([Enum].Parse(GetType(Livelli), dt.Item("PSW1")), Livelli)
End If
If (pass = "pluto") Then
liv = CType([Enum].Parse(GetType(Livelli), dt.Item("PSW2")), Livelli)
End If
If (pass = "pippo") Then
liv = CType([Enum].Parse(GetType(Livelli), dt.Item("PSW3")), Livelli)
End If
End If
Catch er As Exception
MsgBox(er.Message & Environment.NewLine & er.StackTrace)
cn.Close()
End Try
Return liv
End Function
Potete dirmi se è corretto come ho interpretato il problema?