4
votes

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 returning ADODB.DataTypeEnum.adVarChar so this seems valid as well

2
I managed to find this [1]social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/… which would suggest that this is a bug in VS2010 when tragetting .NET 4.0 but no offer of a workaround!Matt Wilko
you should post your comments as an answer.Jim Counts

2 Answers

2
votes

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"

0
votes

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.