我的问题涉及从数据库中的表中返回特定值。我想让它在您登录后显示用户的名字和姓氏。
桌子看起来像这样。
人
UID(PK), FName, LName, Uname, Upass
我如何只返回Fname
andLName
以便我可以将它放在标签中?
这是我当前的代码。请记住,这是针对母版页的。
string strConn = WebConfigurationManager.ConnectionStrings["cloud2"].ConnectionString;
protected void btnlogin2_Click(object sender, EventArgs e)
{
string strCmd = "Select * From Person Where uname = @uname and upass = @upass";
SqlConnection objConn = new SqlConnection(strConn);
SqlCommand objCmd = new SqlCommand(strCmd, objConn);
objCmd.Parameters.AddWithValue("@uname", txtusername.Text);
objCmd.Parameters.AddWithValue("@upass", txtpassword.Text);
using (objConn)
{
objConn.Open();
SqlDataReader objDR = objCmd.ExecuteReader();
if (objDR.HasRows)
{
btnlogin2.Visible = false;
txtusername.Visible = false;
txtpassword.Visible = false;
Response.Redirect("member.aspx");
lblLogin.Text = "Logged in as: Test " ; //Display login name?
}
else
{
btnlogin2.Text = "Failed";
}
}
}