Non ho capito una cosa (o forse molto di più!):
come faccio a leggere da database un dato che non sia una stringa e assegnare quindi il suo valore ad una variabile? Nello specifico vorrei controllare oltre ll UserID e la Password, anche se l'utente è annulato o meno (rappresentato da un valore booleano) e la data di scadenza del suo account.
Con GetString(n) posso recuperare stringhe, ma per le altre tipologie?
Ecco il codice:
<script language="C#" runat="server">
// setta le variabili
public String UserId {
get {
return User.Text;
}
set {
User.Text = value;
}
}
public String Password {
get {
return Pass.Text;
}
set {
Pass.Text = value;
}
}
public bool IsValid {
get {
return Page.IsValid;
}
}
// accesso e verifica su database RA
private void Page_Load(Object sender, EventArgs E) {
if ((Page.IsPostBack)) {
string strDSN = "Provider=sqloledb; Initial Catalog=RA; Data Source=(local); User Id=SA; Password=;";
string strSQL = "SELECT ID_Utente, PWD_Utente, LivelloAccesso, Annullato, DataScadenza FROM Utenti_Azienda WHERE ID_Utente='" + UserId + "'";
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand(strSQL, myConn);
OleDbDataReader dr = null;
try {
myConn.Open();
dr = myCmd.ExecuteReader();
if(dr.Read()) {
if(dr.GetString(1).Trim() == Password.Trim()){Response.Redirect("../accessi/"+dr.GetString(2).Trim()+".aspx");}
else
Message.Text = "Attenzione! La UserID e/o la Password inserite non sono corrette.
L'accesso a RA è stato negato.
";
}
}
catch(Exception myException) {
Message.Text = "Tipologia errore: " + myException.Message;
Message.Text += "
" + strSQL;
}
finally {
myConn.Close();
}
}
}
</script>
Vi prego aiutatemi, sono un ultra-novizio...![]()