public partial class 修改用户信息frm : Form
{
public 修改用户信息frm()
{
InitializeComponent();
}
public string username = "";
public string newpaw ="";//密码
public string newpawagi ="";//确认密码
public string myconnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ErLake.mdb";
private void 修改用户信息frm_Load(object sender, EventArgs e)
{
loadtable();
}
public void loadtable()
{
DataTable mytableall = new DataTable();
string mysqlall = "select * from tb_admin";
OleDbDataAdapter da = new OleDbDataAdapter(mysqlall, myconnstring);
da.Fill(mytableall);
dataGridView1.DataSource = mytableall;
}
//添加选择行改变时,获取行号处理
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
if (this.dataGridView1.SelectionMode!=DataGridViewSelectionMode.FullColumnSelect)
{
int rowindex = dataGridView1.CurrentRow.Index;//获取选中的行号
textBox1.Text = dataGridView1.Rows[rowindex].Cells[].Value.ToString();
//textBox2.Text = dataGridView1.Rows[rowindex].Cells[1].Value.ToString();
//textBox3.Text = dataGridView1.Rows[rowindex].Cells[2].Value.ToString();
textBox2.Focus();//
}
}
private void 修改_Click(object sender, EventArgs e)
{
username=textBox1.Text;//用户名
newpaw = textBox2.Text;//获取密码
newpawagi = textBox3.Text;//获取密码
if (newpaw != newpawagi)
{
MessageBox.Show("两次密码不一致!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
else
{
string sqlcmd = "update tb_admin set 密码 = '"+newpaw+"' where 用户名='"+username+"'";//更新
OleDbConnection myconn = new OleDbConnection(myconnstring);
myconn.Open();
OleDbCommand mycomm = new OleDbCommand(sqlcmd,myconn);
mycomm.ExecuteNonQuery();
MessageBox.Show("密码修改成功!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
loadtable();//加载表
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}