在主页中,要从数据库中检索登录页面值 [英] in the home page, login page value to be retrieved from the database

查看:105
本文介绍了在主页中,要从数据库中检索登录页面值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我创建一个表登录和字段如下;

表名登录

Loginid,名字,姓氏,密码和Lastlogin。

1 ram sam 123 8/12/2012 11:30





然后我创建登录页设计如下;

用户名txtusername.text

密码txtpassword.text



在该运行页面中,当我在用户名中键入1时,在密码中输入123单击按钮,显示消息validloginid和密码。当我在用户名和密码中键入一些值时,它显示loginid和密码不匹配。



它正在工作。



该代码如下;



使用系统;

使用System.Data;

使用System.Configuration;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Web.UI。 HtmlControls;

使用System.Drawing;

使用System.Data.SqlClient;



public partial class _Default :System.Web.UI.Page

{

SqlConnection con = new SqlConnection(Data Source = MOORTHY; Initial Catalog = master; Integrated Security = True);

protected void Page_Load(object sender,EventArgs e)

{



}

protected void Button1_Click(objec t sender,EventArgs e)

{

con.Open();

SqlCommand cmd = new SqlCommand(select entryid,entry from entry其中Loginid =''+ txt_username.Text +''和Password =''+ txt_password.Text +'',con);

SqlDataReader dr = cmd.ExecuteReader();

if(dr.HasRows)

{

Session [Loginid] = txt_username.Text;

dr.Close();

con.Close();

Label3.Text =有效登录ID和密码;

Label3。 ForeColor = System.Drawing.Color.DarkGreen;

//Server.Transfer(\"default2.aspx);

}

else

{

Label3.Text =登录ID不匹配;

Label3.ForeColor = System.Drawing.Color.DarkOrange;



}



}

protected void Button2_Click(object sender,EventArgs e)

{

txt_username.Text =;

txt_password.Text = ;

Label3.Text =;

}

}



然后我设计下一页设计如下;



名字textbox1

姓氏textbox2



当我点击登录页面时它转到该页面的下一页



名字ram(登录表中的值

姓氏sam(登录表中的值)

解决方案

使用会话...

查看我的回答:

如何在asp.net中传递值会话 [ ^

first i create a table login and fields as follows;
table name login
Loginid,Firstname,Lastname,Password and Lastlogin.
1 ram sam 123 8/12/2012 11:30


then i create loginpage design as follows;
username txtusername.text
Password txtpassword.text

in that run page when i type 1 in username and 123 in password and click the button it shows the message validloginid and password. and when i type some value in username and password it shows loginid and password does not match.

it is working.

for that code has follows;

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=MOORTHY;Initial Catalog=master;Integrated Security=True ");
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select Loginid,Password from entry where Loginid = ''" + txt_username.Text + " '' and Password = ''" + txt_password.Text + "''",con);
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows)
{
Session["Loginid"] = txt_username.Text ;
dr.Close();
con.Close();
Label3.Text = "Valid Login ID and Password";
Label3.ForeColor = System.Drawing.Color.DarkGreen;
//Server.Transfer("default2.aspx");
}
else
{
Label3.Text = "Login ID Does Not Match";
Label3.ForeColor = System.Drawing.Color.DarkOrange;

}

}
protected void Button2_Click(object sender, EventArgs e)
{
txt_username.Text = "";
txt_password.Text = "";
Label3.Text = "";
}
}

then i design the next page design as follows;

Firstname textbox1
Lastname textbox2

when i click the login page it goes to next page in that page

Firstname ram (value from the login table
Lastname sam (value from the login table)

解决方案

Use session...
See my answer :
how to pass values thorugh session in asp.net[^]


这篇关于在主页中,要从数据库中检索登录页面值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆