vb 实时错误 -2147217842(80040e4e):怎么解决?(

babyzhou 2005-08-09 10:56:43
救命救命
...全文
473 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
province_ 2005-08-09
  • 打赏
  • 举报
回复
正解!最后一段已经给你解决的提示了,给记录集赋值前要先检查合法性。
原因是赋非法数值的时候记录集会报错误而拒绝更新,你再使用CANCELUPDATE是无意义的,因为此时缓冲里的记录集根本没有任何变化。
crycoming 2005-08-09
  • 打赏
  • 举报
回复
你把一个无效的值赋给了ADO.Recordset 然后就CancelUpdate了,系统就会报错,需要把那个无效的值改成有效值再CancelUpdate
babyzhou 2005-08-09
  • 打赏
  • 举报
回复
can you say chinese? tks ,because my english is very poor
crycoming 2005-08-09
  • 打赏
  • 举报
回复
Symptoms
If you add a new record to an ADO recordset by calling the AddNew method, enter data of an invalid datatype in a control bound to this recordset, and then cancel the change by calling the CancelUpdate method, the CancelUpdate method appears to generate an error due to the invalid datatype, and displays the following run-time error message if you are using ADO 2.1 SP2 or earlier:

Run-time error '-2147217842 (80040e4e)':

The change was canceled during notification; no columns are changed
If you are using ADO 2.5, then the error message may look like this:
Run-time error '-2147217842 (80040e4e)':

Operation was canceled.
This data validation makes sense when calling the Update method, but should not occur when canceling any changes that have been made.



Resolution
To work around this problem, make sure that you enter a valid datatype. For example, using the above-mentioned sample, this unexpected validation error occurs when a string value is entered in a bound control where the underlying database is expecting a numeric value. To work around the error, you only need to check and fix the values that are entered in controls that are bound to numeric fields. The simplest approach is use the IsNumeric function to check the value that is entered in the control and, if the result is False, change the string in the control to a number. Because the record is not saved, the number that is chosen is not important.

To implement this workaround in the Visual Basic project that is described in the "Symptoms" section, add the following code to the CancelUpdate command button's Click procedure as follows:

Private Sub Command2_Click()
If Not IsNumeric(Text1.Text) Then
Text1.Text = 0 'Zero
End If
Adodc1.Recordset.CancelUpdate
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧