尝试更新时表适配器错误
我有一个比较困惑的问题。我的项目使用 VB.net 和 SQL。
我有一个数据库,可以连接到该数据库。我还有一个数据表和数据适配器,我知道它们都可以工作。
我正在尝试更新数据库中的某些内容,但它不起作用。假设列出的所有内容均已正确声明。我做错了什么?
teacher_control_table.Rows(0)("DATA_TeacherLockPasscode") = txtPasscode1.Text
table_adaptor2.Update(teacher_control_table)
最后一行抛出以下异常:
InvalidOperationException 未处理。当传递包含修改行的 DataRow 集合时,更新需要有效的 UpdateCommand。
I have a rather perplexing issue. I am using VB.net and SQL for my project.
I have a database, to which the connection works. I also have a data table and data adaptor, both of which I know work.
I am trying to update something in the database, yet it isn't working. Assume everything listed is declared correctly. What am I doing wrong?
teacher_control_table.Rows(0)("DATA_TeacherLockPasscode") = txtPasscode1.Text
table_adaptor2.Update(teacher_control_table)
That last line throws the following exception:
InvalidOperationException was unhandled. update requires a valid UpdateCommand when passed DataRow collection with modified rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该异常表明您的 UpdateCommand 有问题。
您应该在
table_adaptor2.Update(teacher_control_table
) 上设置断点,并使用即时窗口或监视窗口检查此值,特别是 UpdateCommand 的
.CommandText
、.Connection
和.Parameter
集合,然后验证该命令对于 Teacher_control_table 是否有意义。
The exception indicates there's something wrong with your UpdateCommand.
You should set a breakpoint on
table_adaptor2.Update(teacher_control_table
and with the immidiate window or watch window inspect this valueParticularly the UpdateCommand's
.CommandText
,.Connection
, and.Parameter
Collection.Then verify that the the command makes sense for the teacher_control_table.