Bonjour,
j’aimerai récuperer l’id d’une personne qui se connecte avec l’authentification asp.net . J’affiche bien le “loginname” mais est il possible de récuperer son id sans une autre requete SQL ?
merci
Pour faire une requête il faut :
rajouter cette ligne au fichier web.config
using Microsoft.SqlServer.Server;
using System.Data.SqlClient;
using System.Web.Configuration;
string ConnexionSQL;
protected void Button1_Click(object sender, EventArgs e)
{
ConnexionSQL = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
SqlConnection con = new SqlConnection(ConnexionSQL);
try
{
con.Open();
SqlCommand MyCommand = new SqlCommand();
MyCommand.Connection = con;
MyCommand.CommandText = "SELECT * FROM laTable WHERE (leMembre = N'loginname')"; // vous pouvez aussi faire (Membre = N'" + Membre.Text + "')"
SqlDataReader DR;
DR = MyCommand.ExecuteReader();
while (DR.Read())
{
if (textbox2.Text == DR.GetValue(2).ToString()) // le 2 représente la colonne choisi
{
Label1.Text = "";
Button1.PostBackUrl = "~/Defaut.aspx";
}
else
{
Label1.Text = "Utilisateur ou Mot de Passe incorrect....";
}
}
con.Close();
}
catch(Exception ex)
{
Response.Write("<body><script>alert(\" " + ex.Message + "\");</script></body>");
}
}
Edité le 31/05/2007 à 12:10