开发者

Strange error appending fields to recordset in VS2010 after converting to .NET 4

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:

Error: Missing method 'instance void MYDLLNAME ADODB.Fields::Append(string,valuetype ADODB.DataTypeEnum,int32,valuetype ADODB.FieldAttributeEnum,object)' from class 'ADODB.InternalFields'.

I tried changing my line to just:

resultFields.Append(inColumn.ColumnName, TranslateType(inColumn.DataType)) 

but this gave the same error. The TranslateType function is correctly returnin开发者_开发知识库g ADODB.DataTypeEnum.adVarChar so this seems valid as well


I was getting the same error, which is how i found this question. The fix is described below. I have an application in vs 2010 where I have to build multiple recordsets, some static by appending fields, some where the fields are built from SQL.

To avoid the error, do the following:

For recordsets where you need to append fields, use ADOR.Recordset not ADODB.Recordset.

ADOR is the COM reference "Microsoft ActiveX Data Objects Recordset 2.8 Library"


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜