查询有什么问题?没有更新数据库。 [英] What's wrong with the query? Didn't update the database.

查看:95
本文介绍了查询有什么问题?没有更新数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OleDbDataAdapter adapter = new OleDbDataAdapter();

OleDbCommand command = new OleDbCommand();



OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand();

private void btnaccept_Click(object sender, EventArgs e)
        {
            command = new OleDbCommand("UPDATE Attendance SET remarks=? WHERE studnum=? AND datein=? AND subjcode=?", constring.con);
            command.Parameters.AddWithValue("?", cbremarks.Text);
            command.Parameters.AddWithValue("?", lblnum.Text);
            command.Parameters.AddWithValue("?", cbdate.Text);
            command.Parameters.AddWithValue("?", cbsubject.Text);
            adapter.UpdateCommand = command;
            command.ExecuteNonQuery();



}


}

推荐答案

最可能的原因是WHERE子句失败:很可能在datein值上 - 因为它们精确到毫秒,所以在相同的测试中看起来像是相同的日期和时间是不常见的。



从调试器开始,查看您传递给DB的确切值:然后使用Access查找您希望在DB中更新的值,并在更新完成之前和之后手动比较它们。 br />
同样值得保存ExecuteNonQuery返回的值:在这种情况下,它包含更新记录的数量,如果它为零,则为您提供强有力的线索,它是WHERE子句!
Most likely reason is that the WHERE clause failed: quite possibly on the datein value - since these are accurate to milliseconds, it's common for what looks like the same date and time to not match on an equality test.

Start with the debugger, and look at exactly what values you are passing to the DB: then use Access to look for the values you are expecting to update in the DB and manually compare them before and after the update has been done.
It's also worth saving the value returned by ExecuteNonQuery: in this case it contains the number of updated records, which if it's zero gives you a strong clue it's the WHERE clause!


这篇关于查询有什么问题?没有更新数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆