using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 任务
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
一份作业,开学要交,拖好按钮什么的就闷逼了。完全不会写啊。有没有高手给个完整版的。要有和数据库互动的。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 任务
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
一份作业,开学要交,拖好按钮什么的就闷逼了。完全不会写啊。有没有高手给个完整版的。要有和数据库互动的。
解决方案
40
public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Trim().Length == 0 ) { MessageBox.Show("用户名不能为空!"); return; } else if (textBox2.Text.Trim().Length == 0) { MessageBox.Show("原密码不能为空!"); return; } else if(textBox3.Text.Trim().Length == 0) { MessageBox.Show("新密码不能为空!"); return; } String ConnString = "Server=.;Database=User;Integrated Security=SSPI"; SqlConnection conn = new SqlConnection(ConnString); DataTable dt = new DataTable(); String sql = "SELECT USERNAME,PASSWORD FROM USERINFO where USERNAME= "" + textBox1.Text + "" and PASSWORD = "" + textBox2.Text.Trim()+"""; try { SqlDataAdapter da = new SqlDataAdapter(sql, conn); da.Fill(dt); } catch (Exception Err) { MessageBox.Show(Err.Message); } if (dt.Rows.Count == 0) { MessageBox.Show("旧密码输入错误!"); dt.Dispose(); } else { sql = "UPDATE USERINFO set PASSWORD ="" + textBox3.Text.Trim() + "" where USERNAME= "" + textBox1.Text + """; SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Connection = conn; try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception Err) { MessageBox.Show("更新出现异常!"); } finally { conn.Close(); } MessageBox.Show("密码更新成功!"); } }
要项目不?