public void passwordupdata() { if ((textBox2.Text.Trim())!=(textBox3.Text.Trim())) { MessageBox.Show("你的密码输入不一致","安全提示",MessageBoxButtons.OK,MessageBoxIcon.Warning); return;
} if (textBox3.Text.Length < 6) { MessageBox.Show("密码过短,请输入大于6位数字的密码"); return; } try { sqlcon.Open(); SqlCommand scd = new SqlCommand("update ReadPassword_view set 密码='" + textBox2.Text.Trim() + "' where 读者编号='" + public_Class.NumID + "'", sqlcon); int res = scd.ExecuteNonQuery(); string s = res > 0 ? "操作成功!" : "找不到该用户"; MessageBox.Show(s); } catch (Exception ex) { MessageBox.Show("操作失败,请检查网络连接是否正常!"); } finally { if (sqlcon.State == ConnectionState.Open) sqlcon.Close(); } }
你的win form程序。错误一堆。 win form不是 protected void Page_Load(object sender, EventArgs e),是一般默认名称是XX_Load一般也没有Request.QueryString,也不会是Console.WriteLine("<script language=javascript>alert('请先确定修改的用户名称')"); 你把web和win 结合了。难道叫 Win Web Form ?
比如:修改密码的方法(一般是封装其他的模块中。): protected int SetPassWord(string userId,string passWord) { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;user id=sa;password=密码;initial catalog=数据库名;");//数据库连接,修改你自己的连接 SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "Update User set UserPassWord=@UserPassWord Where UserId=@UserId";//修改为你自己的表名和字段 cmd.Parameters.Add("@UserPassWord", SqlDbType.VarChar).Value = passWord; cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = userId; try { if (cmd.Connection.State != ConnectionState.Open) cmd.Connection.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { if (cmd.Connection.State != ConnectionState.Closed) cmd.Connection.Open(); } } 点击修改密码按钮时的方法: protected void Btn_Click(object sender,EventArgs e) { SetPassWord(用户的ID,用户的新密码);//调用修改密码的方法。 }如果你不清楚,怎么连接数据库,不清楚@UserId,@PassWord是什么?不清楚怎么执行SQL命令。不清楚。建议:你先认真看看书,你会收获很大。就会发现这个很简单了。
首先:判断 新密码与密码确认是否一致!
再者:查询数据库,判断原密码是否输入正确!
最后:更新数据库,用新密码Update原密码!
set [password column name]='New Password'
where [conditions]
例如,首先判断用户是否输入的以上的所有信息。
然后,用户名和旧的密码是否正确。
新的密码和确实密码是否一致,以及新密码和旧密码是否不同。
如果都通过。使用sqlconnection连接到数据库。
使用sqlcommand更新到数据库。
sql语句就更简单的
update table_name
set pwd = @pwd
where account = @account
例如,首先判断用户是否输入的以上的所有信息。
然后,用户名和旧的密码是否正确。
新的密码和确实密码是否一致,以及新密码和旧密码是否不同。
如果都通过。使用sqlconnection连接到数据库。
使用sqlcommand更新到数据库。
sql语句就更简单的
update table_name
set pwd = @pwd
where account = @account
Win Form里面的界面工具箱没有验证控件啊,怎么进行判断呢
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace zdjl
{
public partial class yuanMiMa : Form
{
OledbHelper dataconn = new OledbHelper();
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["operator_id"] != null)
{
this.yongHuMingCheng.Text = Request.QueryString["operator_ID"];
this.yongHuMingCheng.Enabled = false;
}
else
{
Console.WriteLine("<script language=javascript>alert('请先确定修改的用户名称')");
}
} public yuanMiMa()
{
InitializeComponent();
} private void quXiaoXiuGai_Click(object sender, EventArgs e)
{
Application.Exit();
} private void queRenXiuGai_Click(object sender, EventArgs e)
{ OledbHelper.ExecuteReader("update operator set operator_mima='" + this.miMaGaiWei.Text + "'where operator_id=" + this.yongHuMingCheng.Text);
//dataconn.eccom("update tb_User set password='" + this.txtNewPassword.Text + "'where UserName=" + this.txtUserID.Text);
Console.WriteLine("<script language=javascript>alert('您已经修改成功');opener.location.reload();window.close()</script>");
}
// yongHuGuanLi yonghuguanli= new yongHuGuanLi();`
//yonghuguanli. Show();
}
}这是我写的,出错提示错误 1当前上下文中不存在名称“Request” D:\My Documents\Visual Studio 2005\Projects\zdjl\zdjl\xiuGaiMiMa.cs 18 17 zdjl
错误 2 非静态的字段、方法或属性“zdjl.OledbHelper.ExecuteReader(string)”要求对象引用 D:\My Documents\Visual Studio 2005\Projects\zdjl\zdjl\xiuGaiMiMa.cs 44 13 zdjl
using(SqlConnection conn = new SqlConnection(connStr))
{
string sql = "select * from Tb where username=''";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.HasRows && dr.Read())
{
}
dr.Close();
conn.Close();
}
//先查询密码是否一致再修改
{
private readonly string sql = "server=.;database=QQ;uid=sa;pwd=87936260";
private SqlConnection cn;
private SqlCommand cmd;
public void Open()
{
cn = new SqlConnection(sql);
cn.Open();
}
public void Close()
{
if (cn != null)
{
cn.Close();
cn.Dispose();
}
}
public void RunSql(string strSql)
{
Open();
cmd = new SqlCommand(strSql, cn);
cmd.ExecuteNonQuery();
Close();
}
public string RunSqlReturn(string strSql)
{
string strReturn="";
Open();
try
{
cmd=new SqlCommand(strSql,cn);
strReturn=cmd.ExecuteScalar().ToString();
}
catch{}
Close();
return strReturn;
}private void button1_Click(object sender, EventArgs e)
{
string sql1 = "select * from Users where User_Name='" + textBox1.Text + "' and User_Pwd='" + textBox2.Text + "'";
string sql2 = "update Users set User_Pwd='" + textBox3.Text + "'where User_Name='" + textBox1.Text + "'";
string strUserId = sql.RunSqlReturn(sql1);
if (!Equals(strUserId, ""))
{
if (textBox3.Text != textBox4.Text)
{
label5.Visible = true;
label5.Text = "两次输入\n的密码不一致!";
return;
}
else
{
sql.RunSql(sql2);
label5.Visible = false;
MessageBox.Show("密码修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Close();
}
}
else MessageBox.Show("账号或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
长了点。有时间慢慢看看吧
public void passwordupdata()
{
if ((textBox2.Text.Trim())!=(textBox3.Text.Trim()))
{
MessageBox.Show("你的密码输入不一致","安全提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
if (textBox3.Text.Length < 6)
{
MessageBox.Show("密码过短,请输入大于6位数字的密码");
return;
}
try
{
sqlcon.Open();
SqlCommand scd = new SqlCommand("update ReadPassword_view set 密码='" + textBox2.Text.Trim() + "' where 读者编号='" + public_Class.NumID + "'", sqlcon); int res = scd.ExecuteNonQuery(); string s = res > 0 ? "操作成功!" : "找不到该用户";
MessageBox.Show(s);
}
catch (Exception ex)
{
MessageBox.Show("操作失败,请检查网络连接是否正常!");
}
finally
{
if (sqlcon.State == ConnectionState.Open)
sqlcon.Close();
}
}
win form不是 protected void Page_Load(object sender, EventArgs e),是一般默认名称是XX_Load一般也没有Request.QueryString,也不会是Console.WriteLine("<script language=javascript>alert('请先确定修改的用户名称')");
你把web和win 结合了。难道叫 Win Web Form ?
{ SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;user id=sa;password=密码;initial catalog=数据库名;");//数据库连接,修改你自己的连接
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "Update User set UserPassWord=@UserPassWord Where UserId=@UserId";//修改为你自己的表名和字段
cmd.Parameters.Add("@UserPassWord", SqlDbType.VarChar).Value = passWord;
cmd.Parameters.Add("@UserId", SqlDbType.VarChar).Value = userId;
try
{
if (cmd.Connection.State != ConnectionState.Open)
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
} finally
{
if (cmd.Connection.State != ConnectionState.Closed)
cmd.Connection.Open();
} }
点击修改密码按钮时的方法:
protected void Btn_Click(object sender,EventArgs e)
{
SetPassWord(用户的ID,用户的新密码);//调用修改密码的方法。
}如果你不清楚,怎么连接数据库,不清楚@UserId,@PassWord是什么?不清楚怎么执行SQL命令。不清楚。建议:你先认真看看书,你会收获很大。就会发现这个很简单了。
cmd.ExecuteNonQuery();
==》
return cmd.ExecuteNonQuery();
首先是数据库的操作类,把SQLHELPER看懂,并能自己扩展功能
然后学习怎么用这个类进行数据库操作。
然后就是其他界面、逻辑的学习,就比如你这种登录什么的学习
循序渐进,才能学好,每样东西都是靠不断的动手练手再动手
string struser = "select * from admin where name='" + textBox1.Text + "'";
DataSet ds = JX.DBUtility.DbHelperSQL.Query(struser);
if (ds.Tables[0].Rows.Count > 0)
{
if (textBox2.Text == ds.Tables[0].Rows[0]["mima"].ToString())
{
if (textBox3.Text == textBox4.Text)
{
JX.Model.admin ad = new JX.Model.admin();
ad.aid = Convert.ToInt32(ds.Tables[0].Rows[0]["aid"]);
ad.mima = textBox4.Text;
ad.name = textBox1.Text;
ad.quanxian = Convert.ToInt32(ds.Tables[0].Rows[0]["quanxian"]);
JX.BLL.admin adb = new JX.BLL.admin();
adb.Update(ad);
MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Close();
}
else
{
MessageBox.Show("两次新密码不相同,请从新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
textBox3.Text = "";
textBox4.Text = "";
textBox3.Focus();
}
} else
{
MessageBox.Show("旧密码输入不正确,请从新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox2.Focus();
}
}
else
{
MessageBox.Show("用户名输入不正确,请从新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox1.Focus();
}数据库连接上边有
然后写update语句
最后执行sql语句
那么就根据 用户名 取出原密码
txtOldPwd //原密码
txtNewPwd //新密码
txtSure //确认密码string _conStr ="User ID=sa;Password=sa;Persist Security Info=False;Data
Source=192.168.0.1;Initial Catalog=UserInfo(表名)";//连接字符串 private void btnChangePassword_Click(object sender, EventArgs e)
{
using(DataClassesContext db =new DataClassesContext(_conStr))
{
var name =(from u in db.UserInfo where u.UserName == txtUserName.text select u.UserName ).FirstOrDefault();
string oldPwd =db.UserInfo.SingleOrDefault(t=>t.UserName==name).UserPwd.toString();
if(txtOld.text==oldPwd&& txtNewPwd.text==txtSure.text)
{
UserInfo user = db.UserInfo.SingleOrDefault(t => t.UserName == name);
user.UserPassword = txtOK.Text;
db.SubmitChanges();
MessageBox.Show("密码修改成功!");
}
else
{
if (txtoldPwd.Text != _Pwd)
{
MessageBox.Show("原密码输入错误!");
}
if (txtOK.Text != txtnewPwd.Text)
{
MessageBox.Show("两次输入不一致,请重新输入!");
}
} }
}
大意了.......