双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

新手求教C# 更新access 数据库的问题

u010671827 u010671827 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
窗体是这样的



单击按钮代码
private void button1_Click(object sender, EventArgs e)
{
DBHelper helper = new DBHelper();
String sql1 = string.Format("select * from employee_log where [员工账号]={0} and [员工密码]={1}",all.all_emid.Trim(),textBox1.Text.Trim());
//String sql2 = string.Format("update [employee_log] set [员工密码]={0} where [员工账号]={1}",textBox1.Text.Trim(),all.all_emid.Trim());
String sql2 = "update employee_log set [员工密码]=" + textBox1.Text + " where [员工账号]=" + all.all_emid + "";
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
{
MessageBox.Show("密码不能为空!");
}
else if (textBox2.Text.Trim() != textBox3.Text.Trim())
{
MessageBox.Show("密码不一致,请核对.");
}
else if (helper.setS(sql1))
{
if (helper.setDS(sql2))
{
MessageBox.Show("修改成功");
}
}
else MessageBox.Show("不存在此密码.");

}
DBHelper 是个连接数据库的类
public class DBHelper
{
private OleDbConnection conn;
private OleDbDataAdapter oda = new OleDbDataAdapter();
private OleDbCommand cmd;
private DataSet myds = new DataSet();
public DBHelper()
{

conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\\visual studio 2010\\Projects\\hotel_management\\hotel_management\\bin\\Debug\\Database1.accdb");
}
public DataSet getDS(string strSQL)//获得数据;
{
conn.Open();
myds = new DataSet();
oda = new OleDbDataAdapter(strSQL, conn);
oda.Fill(myds);
return myds;
}

public DataSet getDS2(string strSQL, int si, int mi)
{
conn.Open();
myds = new DataSet();
oda = new OleDbDataAdapter(strSQL, conn);
oda.Fill(myds, si, mi, "tab1");
conn.Close();
return myds;

}

public bool setDS(string strSQL)//非查询操作;
{
conn.Open();
cmd = new OleDbCommand(strSQL, conn);
cmd.ExecuteNonQuery();
conn.Close();
return true;
}
public bool setS(string strSQL)
{
conn.Open();
cmd = new OleDbCommand(strSQL, conn);
if (cmd.ExecuteReader().HasRows)
{
conn.Close();
return true;
}
else
{
conn.Close();
return false;
}
}


}
然后呢 all.all_emid 是上个窗体登陆时候记录员工账号字段的;

能运行成功,但是就是运行结束后到access 中去查看数据的时候密码没有改变;
我想问问,是我代码什么逻辑问题吗? 我查了好多但是都没发现。想问问,能帮帮我吗,我是新手请帮助下我,谢谢。
...全文
评论 14
收藏 已收藏
分享
返回顶部
u010671827
C# 111,129 成员 642,540 内容