我創建簡單的登錄頁面,但我與用戶ID登錄得到了問題如何獲得登錄用戶ID C#
public partial class LoginwithEncryption : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand(
"select * from dbo.UserInfo where Login [email protected] and [email protected]", con);
cmd.Parameters.AddWithValue("@Login", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Response.Redirect("StartPage.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation",
"<script language='javascript'>alert('Invalid UserName and Password')</script>");
}
}
}
我怎樣才能獲得的用戶ID登錄(IM能夠登錄)後?我試過一些方法,但它不會工作;(
我的數據庫:
你有什麼錯誤? – Steve
你嘗試過什麼,但沒有成功? – kaptan
兩個答案(來自用戶luke2012和user733659)幫助我,謝謝你幫助新手! – user2121038