各位高手帮个忙,我是新手,想用C#.NET实现个找回密码的功能,就是根据帐...
发布网友
发布时间:2024-09-29 09:49
我来回答
共4个回答
热心网友
时间:2024-09-30 06:18
string userid="Select Useranswer from getpassword where Userid = '" +Textbox1.Text.Tostring()+"'"
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds);
热心网友
时间:2024-09-30 06:16
string userid="Select Useranswer from getpassword where Userid = '" +Textbox1.Text.Tostring()+"'"
DataSet ds = new DataSet(userid);
SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);
adapter.Fill(ds); 这样就OK了
热心网友
时间:2024-09-30 06:12
//帮你编了个完整,简单易懂代码:
//数据库跟你的一样,我用的是Access的数据库
//前台代码
//=============================
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="getPwd.aspx.cs" Inherits="getPwd" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div runat="server" id="u2">
账号:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="提交" OnClick="Button1_Click" /><br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label><br />
<br />
</div>
<div runat="server" id="u1">
账号:<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br />
<br />
问题:<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br />
<br />
您的回答:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button2" runat="server" Text="提交" OnClick="Button2_Click" /><br />
<br />
<asp:Label ID="Label4" runat="server"></asp:Label><br />
<br />
</div>
<div id="u3" runat="server">
您的密码为:<asp:Label ID="Label5" runat="server" ForeColor="Red"></asp:Label>
</div>
</div>
</form>
</body>
</html>
//==============================
//后台代码
//==============================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.OleDb;
public partial class getPwd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
u1.Visible = false;
u2.Visible = true;
u3.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string id = TextBox1.Text.Trim();
string sql = "select * from getpassword where UserId='" + id + "'";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("user.mdb"));
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "info");
if (ds.Tables["info"].Rows.Count != 0)
{
u1.Visible = true;
u2.Visible = false;
Label2.Text = id;
Label3.Text = ds.Tables["info"].Rows[0]["Userquestion"].ToString();
}
else
{
Label1.Text = "账号不存在!";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string answer = TextBox2.Text.Trim();
string sql = "select * from getpassword where UserId='" + Label2.Text + "' and Useranswer='" + answer + "'";
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("user.mdb"));
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "getPwd");
if (ds.Tables["getPwd"].Rows.Count != 0)
{
u1.Visible = false;
u2.Visible = false;
u3.Visible = true;
Label5.Text = ds.Tables["getPwd"].Rows[0]["UserPwd"].ToString();
}
else
{
Label4.Text = "您的回答不正确";
}
}
}
热心网友
时间:2024-09-30 06:17
不会