高手指点!c#编写一个用户修改密码的界面,和数据库连接起来

用户登陆后,需要修改自己的密码,在修改密码界面有用户名,原始密码,新密码,和重复密码四个TXT,自己写了一些代码,但是实现不了,在网上也看到一些代码,觉得不合适,小弟是菜鸟而且分也不是很多,希望g能得到高手的指点!最好有一个参考程序!

自己已经测试过

using System;
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 KtvMng
{
public partial class UpdPwd : Form
{
SqlConnection conn;
SqlCommand comm;
string userid = "";
public UpdPwd(string UserId)
{
InitializeComponent();
userid = UserId;
}

private void btnUpd_Click(object sender, EventArgs e)
{
//连接数据库
conn = new SqlConnection("server=localhost;database=test;Integrated Security=true");
try
{
conn.Open();
}
catch
{
MessageBox.Show("连接数据库失败!");
}
string strQuery="SELECT COUNT (*) FROM UserInfom Where KtvID='"+userid+"' AND UserPwd='"+txtOriPwd.Text+"'";
comm=new SqlCommand (strQuery,conn);
if ((int)comm.ExecuteScalar() > 0)//修改密码之前先查询原始密码是否正确
{
if (txtNewPwd.Text == txtAgainPwd.Text)//两次密码是否想等
{
string strUpdPwd = "UPDATE UserInfom set UserPwd='" + txtNewPwd.Text + "'Where KtvID='"+userid+"'";
comm = new SqlCommand(strUpdPwd, conn);
int result = comm.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("密码修改成功");
}
else
{
MessageBox.Show("密码修改失败!");
return;
}
}
else
{
MessageBox.Show("两次密码输入不一致!");
txtOriPwd.Focus();
txtAgainPwd.Clear();
txtNewPwd.Clear();
txtOriPwd.Clear();
return;
}
}
}
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答