奇怪的错误附加字段VS2010与Recordset转换为.NET 4的后 [英] Strange error appending fields to recordset in VS2010 after converting to .NET 4
问题描述
我从这个网站的一些code codeProjectLink 转换一个数据表,以一个记录。这code一直工作正常,直到我换到.NET 4(是previously 2),现在当我叫下面一行:
I have some code from this site CodeProjectLink to convert a datatable to a recordset. This code had been working fine until I changed to .NET 4 (was previously 2), now when I call the following line:
Dim result As New ADODB.Recordset()
result.CursorLocation = ADODB.CursorLocationEnum.adUseClient
Dim resultFields As ADODB.Fields = result.Fields
Dim inColumns As System.Data.DataColumnCollection = inTable.Columns
For Each inColumn As DataColumn In inColumns
' The next line gives the error
resultFields.Append(
inColumn.ColumnName,
TranslateType(inColumn.DataType),
inColumn.MaxLength,
IIf(inColumn.AllowDBNull,
ADODB.FieldAttributeEnum.adFldIsNullable,
ADODB.FieldAttributeEnum.adFldUnspecified),
Nothing)
Next
我得到这个奇怪的错误:
I get this strange error:
错误:缺少方法实例无效MYDLLNAME ADODB.Fields ::追加(字符串值类型ADODB.DataTypeEnum,INT32,值类型ADODB.FieldAttributeEnum,对象)从级ADODB.InternalFields。
我试图改变我行只是:
resultFields.Append(inColumn.ColumnName, TranslateType(inColumn.DataType))
不过这给了同样的错误。该TranslateType功能是正确返回ADODB.DataTypeEnum.adVarChar所以这似乎也有效
but this gave the same error. The TranslateType function is correctly returning ADODB.DataTypeEnum.adVarChar so this seems valid as well
推荐答案
对于任何有兴趣在此我设法通过创建一个认为我可以从我的VB6应用程序访问公共数据表一个COM暴露自定义类工作的这一轮。这需要进行转换的要求,以一个记录,因为我没有做任何数据绑定等,因此对于所有的情景,但是一个良好的坚实工作围绕在我的情况,没办法了。
For anyone interested in this I have managed to work round this by creating a COM exposed custom class that holds a public DataTable that I can access from my VB6 app. This takes out the requirement for conversion to a Recordset as I am not doing any data binding etc. so not a solution for all scenarios but a good solid work around in my case.
这篇关于奇怪的错误附加字段VS2010与Recordset转换为.NET 4的后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!