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
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.