1

私はvs 2008、フレームワーク3.5でc#を使用しています。ユーザー名を保存する必要があり、ユーザーがログインすると、彼/彼女の姓と名が表示され、この時点で保存できます。それが私が望むものですただし、ユーザー名ではなく、姓と名だけをユーザーに表示する必要があります。これが私のコードです、事前に感謝します。

//code in the login
ClPersona login = new ClPersona();
bool isAuthenticated = login.sqlLogin1((txtUsuario.Text), (txtPassword.Text));
if (isAuthenticated)
{
Session["sesionicontrol"] = login.NombreUsuario;
Response.Redirect("../MENU/menu1.aspx");
}

//code in the form where shows the username but I want the first and last name

public partial class menu2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblNombreUsuario.Text = (string)Session["sesionicontrol"]; 
if (!IsPostBack)


//ClPersona class

public Boolean sqlLogin1(string nombreUsuario, string password)
{
string stSql = "select * from usuarios where usuario='" + nombreUsuario + "' and
pass='" + password + "'and id_rol='1'";
Bd miBd = new Bd();
DataTable dt = miBd.sqlSelect(stSql);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
//return ds;
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
4

1 に答える 1

0

2 つのセクションを修正する

初め

if (isAuthenticated)
{
Session["YouObject"] = login;//<--

Session["sesionicontrol"] = login.NombreUsuario;
Response.Redirect("../MENU/menu1.aspx");
} 

2番

protected void Page_Load(object sender, EventArgs e)
{
   if(Session["YouObject"] != null)
   { 
     ClPersona obj = (ClPersona )Session["YouObject"];
     lblNombreUsuario.Text = string.Format("{0}-{1}", obj.FirstName, obj.LastName ) 


   }

      lblNombreUsuario.Text = (string)Session["sesionicontrol"];
     ....
}
于 2012-09-05T14:17:04.907 に答える