帮助!将数据从一列复制到类似记录集中的同一列时出错
我有一个例程,它读取一个记录集,并在类似的记录集中添加/更新行。该例程首先将列复制到新记录集:
这是创建新记录集的代码..
For X = 1 To aRS.Fields.Count
mRS.Fields.Append aRS.Fields(X - 1).Name, aRS.Fields(X - 1).Type, aRS.Fields(X - _
1).DefinedSize, aRS.Fields(X - 1).Attributes
Next X
非常简单。注意名称、类型、定义大小和大小的复制。属性...
在代码的更下方,(并且没有任何内容可以修改之间的任何列..)我将一行的值复制到新记录集中的一行,如下所示:
For C = 1 To aRS.Fields.Count
mRS.Fields(C - 1) = aRS.Fields(C - 1)
Next C
当它到达最后一列时这是一个数字,它会显示“多步操作生成错误”消息。
我知道 MS 说这是由提供程序生成的错误,在本例中为 ADO 2.8。此时也没有与数据库的开放连接。
我正在拉我剩下的一点头发......(此时我并不真正关心列索引在一个循环中是“X”而在另一个循环中是“C”......我当我解决真正的问题后会更改它......)
I have a routine which reads one recordset, and adds/updates rows in a similar recordset. The routine starts off by copying the columns to a new recordset:
Here's the code for creating the new recordset..
For X = 1 To aRS.Fields.Count
mRS.Fields.Append aRS.Fields(X - 1).Name, aRS.Fields(X - 1).Type, aRS.Fields(X - _
1).DefinedSize, aRS.Fields(X - 1).Attributes
Next X
Pretty straight forward. Notice the copying of the name, Type, DefinedSize & Attributes...
Further down in the code, (and there's nothing that modifies any of the columns between.. ) I'm copying the values of a row to a row in the new recordset as such:
For C = 1 To aRS.Fields.Count
mRS.Fields(C - 1) = aRS.Fields(C - 1)
Next C
When it gets to the last column which is a numeric, it craps with the "Mutliple-Step Operation Generated an error" message.
I know that MS says this is an error generated by the provider, which in this case is ADO 2.8. There is no open connect to the DB at this point in time either.
I'm pulling what little hair I have left over this one... (and I don't really care at this point that the column index is 'X' in one loop & 'C' in the other... I'll change it later when I get the real problem fixed...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在打开合成记录集之前,您必须为
adDecimal
和adNumeric
字段设置Precision
和NumericScale
仅供参考:您可能获取一个记录集,其中的字段没有数据库中的名称,例如
,但 ADO 不允许在
Append
方法上使用空名称。您还可能从数据库中获取包含重复字段的记录集,例如,在您的情况下,该记录集也会在
Append
上崩溃。You have to set
Precision
andNumericScale
foradDecimal
andadNumeric
fields before opening synthetic recordset like thisFYI: you might be get a recordset with a field that has no name from the database e.g.
but ADO will not allow an empty name on
Append
method. You might also get a recordset with duplicate fields from the database e.g.which in your case will bomb out on
Append
too.猜测 2:正确的行应该是
我的猜测是您有一个 null 并且您没有正确对待 dbnull 类型。
Guess 2 : the correct line should be
My guess is you have have a null and you are not treating the dbnull type right.
请参阅我关于寻找替代方法的评论,但直接的答案是需要设置
Field
对象的Precision
和NumericScale
属性。这是错误的重现,取消注释这两行以修复错误:Please see my comments about finding an alternative approach but the straight answer is the
Field
objects'Precision
andNumericScale
properties need to be set. Here's a repro of your error, uncomment the two lines to fix the error: