locked
fields.append

    Question

  • I get the following error when running a program in Visual Studio 2010 Express.  Could someone please help me out?

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

    Here is the code:

    With

     

     

    rsInputBuffer

    .CursorLocation = ADODB.CursorLocationEnum.adUseClient

    rsInputBuffer.Fields.Append(

     

    "Comment", ADODB.DataTypeEnum.adBoolean)

     

     

    rsInputBuffer.Fields.Append("LineData", ADODB.DataTypeEnum.adChar, 100)

    rsInputBuffer.Open()

     

     

    End With

    Thanks,

    Vickie


    Vickie Hunt United Micro Data, Inc. Programmer vickie@umdirect.net
    Tuesday, January 04, 2011 5:27 PM

Answers

  • Seems that I have solved the problem adding a reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library"

    Hope this help

    Tix

    • Proposed as answer by Jordan B Tuesday, August 09, 2011 11:24 PM
    • Marked as answer by Mike FengModerator Friday, October 07, 2011 6:10 AM
    Wednesday, April 27, 2011 12:30 PM
  • So it sounds like there are two answers here:

    When using Visual Studio 2010 , you can change the Target .NET Framework of your project from ".NET Framework 4.0" to ".NET Framework 3.5"

    or ".NET Framework 3.5 Client Profile"

    Or you can do as tix61 suggests and change your reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library"

    • Proposed as answer by Jordan B Tuesday, August 09, 2011 11:24 PM
    • Marked as answer by Mike FengModerator Friday, October 07, 2011 6:10 AM
    Tuesday, August 09, 2011 11:23 PM

All replies

  • I wasn't able to repro the error with your code. On what line does the error occur? Also, where in your code is rsInputBuffer defined/instantiated?
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, January 05, 2011 3:10 PM
  • I get it on the line: 

    rsInputBuffer.Fields.Append(

     

    "Comment", ADODB.DataTypeEnum.adBoolean)

    The rsInputBuffer is defined as:

    Public

     

     

    rsInputBuffer As New ADODB.Recordset

    Vickie


    Vickie Hunt United Micro Data, Inc. Programmer vickie@umdirect.net
    Wednesday, January 05, 2011 3:35 PM
  • This is the code that I have and it seems to work fine:

        Dim rsInputBuffer As New ADODB.Recordset
        rsInputBuffer.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rsInputBuffer.Fields.Append("Comment", ADODB.DataTypeEnum.adBoolean)
        rsInputBuffer.Fields.Append("LineData", ADODB.DataTypeEnum.adChar, 100)
        rsInputBuffer.Open()
    
    


    Did you add a Reference for ADODB to your project?


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, January 05, 2011 4:07 PM
  • Yes.  I have included the following reference in my project:

    Microsoft ADO Ext. 6.0 for DLL and Security

    Is ther something else I can do?

    -Vickie


    Vickie Hunt United Micro Data, Inc. Programmer vickie@umdirect.net
    Wednesday, January 05, 2011 5:03 PM
  • I also have the following reference to my project:

    Microsoft AcitveX Data Objects 6.0 Library

    -Vickie


    Vickie Hunt United Micro Data, Inc. Programmer vickie@umdirect.net
    Wednesday, January 05, 2011 5:12 PM
  • I also have the following reference to my project:

    Microsoft AcitveX Data Objects 6.0 Library

    -Vickie


    Vickie Hunt United Micro Data, Inc. Programmer vickie@umdirect.net


    Actually, yes this is the one you need. You don't need the ADO extensions unless you're creating or modifying database objects.

    I can't explain the error because I can't reproduce it (unless I'm doing something different). Is there a reason why you are using Classic ADO instead of ADO.NET (e.g. a DataTable)?


    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, January 05, 2011 5:51 PM
  • I am trying to convert existing Visual Basic code to Visual Studio 2010 Express.  If there is an easier/better way with the same results I can change the code.  I am trying to learn Visual Studio Express and am so new I do not know all of the functions yet.

    -Vickie


    vhunt
    Wednesday, January 05, 2011 7:12 PM
  • For an in-memory data store, a DataTable would probably be the closest thing to an ADO Recordset:

    http://msdn.microsoft.com/en-us/library/system.data.datatable(v=VS.100).aspx

     


    Paul ~~~~ Microsoft MVP (Visual Basic)
    • Proposed as answer by Bin-ze Zhao Thursday, January 06, 2011 7:59 AM
    Wednesday, January 05, 2011 7:34 PM
  • Hi Paul, I can re-create this issue in Visual Studio 2010 using a project targeting the .NET Framework 4.0 (CLR 4.0). This does not occur in a project using Visual Studio 2008 or a project in Visual Studio 2010 targeting the .NET Framework 3.5 or lower (CLR 2.0).

    A very simple example:

    Imports ADODB
    Imports ADODB.CursorLocationEnum
    Imports ADODB.CursorTypeEnum
    Imports ADODB.DataTypeEnum
    Imports ADODB.FieldAttributeEnum
    Imports ADODB.PersistFormatEnum
    
    Public Class Form1
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      ' Test building ADO Recordset on the fly
      Dim result As ADODB.Recordset = New ADODB.Recordset()
    
      Try
       'NewRS()
    
       result.CursorLocation = ADODB.CursorLocationEnum.adUseClient
       Dim resultFields As ADODB.Fields = result.Fields
       resultFields.Append("FirstColumn", ADODB.DataTypeEnum.adVarChar, 255, adFldIsNullable)
    
    
      Catch ex As Exception
       MsgBox(ex.Message)
    
      End Try
    
      MsgBox("rs created.")
    
      'Return result
     End Sub
    End Class
    
    

    I agree with you that ADO.NET DataTables are probably the best to use for an in-memory data store (and more importantly, closest to an ADO Recordset), but there's a very popular COM-based application used by over 500 million users every day (Microsoft Office) that still requires ADO Recordsets for binding Pivot Caches and creating Querytables programmatically. I would love to be able to get rid of code that converts from ADO.NET DataTables to ADO Recordsets, but it's not in the cards today.

    This looks to be a bug in .NET Framework 4.

    I am having this problem too, any ideas on how to report it to Microsoft?

    • Edited by Jordan B Tuesday, January 11, 2011 11:02 PM grammar
    Tuesday, January 11, 2011 11:00 PM
  • I couldn't repro the problem in VS 2010, but I will try it with a new project targeting 4.0.
    Paul ~~~~ Microsoft MVP (Visual Basic)
    Wednesday, January 12, 2011 1:02 AM
  • I tried this on a different machine and it worked. So something is installed on the offending machine that is causing the issue. This is troubling, mainly because people seemed to have reported the same issue within days of each other. I wonder if it is related to an update. I will keep digging on this one and see if I can figure out what's different between the two machines.
    Wednesday, January 12, 2011 3:56 PM
  • I tried this on a different machine and it worked. So something is installed on the offending machine that is causing the issue. This is troubling, mainly because people seemed to have reported the same issue within days of each other. I wonder if it is related to an update. I will keep digging on this one and see if I can figure out what's different between the two machines.

    I'm currently experiencing this on a project (VS2010 ) as a runtime error.

     

    We are running .net4 and are referencing "Microsoft ActiveX Data Objects 2.8 Library" on a fully patched XP machine.

    When referencing "Microsoft ActiveX Data Objects 2.7 Library" it works fine.

     

    Code we are using 

    ============================

     


        /// <summary>
        /// Converts a datatable to an ADODB.Recordset
        /// </summary>
        /// <param name="dataTable"></param>
        /// <returns></returns>
        private static ADODB.Recordset ToRecordset(this DataTable dataTable)
        {
            ADODB.Recordset result = new ADODB.Recordset();
            result.CursorLocation = ADODB.CursorLocationEnum.adUseClient;

            ADODB.Fields resultFields = result.Fields;
            System.Data.DataColumnCollection inColumns = dataTable.Columns;

            foreach (DataColumn inColumn in inColumns)
            {
    //Fails here
                resultFields.Append(
                    inColumn.ColumnName
                    , TranslateType(inColumn.DataType)
                    , inColumn.MaxLength
                    , inColumn.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable :
                                             ADODB.FieldAttributeEnum.adFldUnspecified
                    , Type.Missing
                    );
            }

            result.Open(System.Reflection.Missing.Value
                    , System.Reflection.Missing.Value
                    , ADODB.CursorTypeEnum.adOpenStatic
                    , ADODB.LockTypeEnum.adLockOptimistic, 0);

            foreach (DataRow dr in dataTable.Rows)
            {
                result.AddNew(System.Reflection.Missing.Value,
                              System.Reflection.Missing.Value);

                for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++)
                {
                    resultFields[columnIndex].Value = dr[columnIndex];
                }
            }

            return result;
        }

        private static ADODB.DataTypeEnum TranslateType(Type columnType)
        {
            switch (columnType.UnderlyingSystemType.ToString())
            {
                case "System.Boolean":
                    return ADODB.DataTypeEnum.adBoolean;

                case "System.Byte":
                    return ADODB.DataTypeEnum.adUnsignedTinyInt;

                case "System.Char":
                    return ADODB.DataTypeEnum.adWChar;

                case "System.DateTime":
                    return ADODB.DataTypeEnum.adDBTimeStamp;

                case "System.Decimal":
                    return ADODB.DataTypeEnum.adDecimal;

                case "System.Double":
                    return ADODB.DataTypeEnum.adDouble;

                case "System.Int16":
                    return ADODB.DataTypeEnum.adSmallInt;

                case "System.Int32":
                    return ADODB.DataTypeEnum.adInteger;

                case "System.Int64":
                    return ADODB.DataTypeEnum.adBigInt;

                case "System.SByte":
                    return ADODB.DataTypeEnum.adTinyInt;

                case "System.Single":
                    return ADODB.DataTypeEnum.adSingle;

                case "System.UInt16":
                    return ADODB.DataTypeEnum.adUnsignedSmallInt;

                case "System.UInt32":
                    return ADODB.DataTypeEnum.adUnsignedInt;

                case "System.UInt64":
                    return ADODB.DataTypeEnum.adUnsignedBigInt;

                case "System.String":
                default:
                    return ADODB.DataTypeEnum.adVarWChar;
            }
        }

    //Dummy Datatable
    public string GetTestData()
            {
                var dt = new DataTable();
                dt.TableName = "TESTtableName";

                dt.Columns.Add("TestInteger"typeof(int));
                dt.Columns.Add("TestBoolean"typeof(Boolean));
                dt.Columns.Add("TestByte"typeof(byte));
                dt.Columns.Add("TestDate"typeof(DateTime));
                dt.Columns.Add("TestDecimal"typeof(decimal));
                dt.Columns.Add("TestDouble"typeof(double));
                dt.Columns.Add("TestLong"typeof(long));
                dt.Columns.Add("TestShort"typeof(short));
                dt.Columns.Add("TestSingle"typeof(Single));
                dt.Columns.Add("TestString"typeof(string));


                {
                    DataRow row = dt.NewRow();
                    row.SetField("TestInteger"int.MinValue);
                    row.SetField("TestBoolean"true);
                    row.SetField("TestByte"byte.MinValue);
                    row.SetField("TestDate"DateTime.Now);
                    row.SetField("TestDecimal"Decimal.MinValue);
                    row.SetField("TestDouble"Double.MinValue);
                    row.SetField("TestLong"long.MinValue);
                    row.SetField("TestShort"short.MinValue);
                    row.SetField("TestSingle"Single.MinValue);
                    row.SetField("TestString", "asdasd");
                    dt.Rows.Add(row);
                }
                {
                    DataRow row = dt.NewRow();
                    row.SetField("TestInteger"int.MaxValue);
                    row.SetField("TestBoolean"false);
                    row.SetField("TestByte"byte.MaxValue);
                    row.SetField("TestDate"DateTime.Now);
                    row.SetField("TestDecimal"Decimal.MaxValue);
                    row.SetField("TestDouble"Double.MaxValue);
                    row.SetField("TestLong"long.MaxValue);
                    row.SetField("TestShort"short.MaxValue);
                    row.SetField("TestSingle"Single.MaxValue);
                    row.SetField("TestString", "asdasd");
                    dt.Rows.Add(row);
                }
                {
                    DataRow row = dt.NewRow();
                    row.SetField("TestInteger"int.MaxValue);
                    row.SetField("TestBoolean"false);
                    row.SetField("TestByte"byte.MaxValue);
                    row.SetField("TestDate"DBNull.Value);
                    row.SetField("TestDecimal"Decimal.MaxValue);
                    row.SetField("TestDouble"DBNull.Value);
                    row.SetField("TestLong"long.MaxValue);
                    row.SetField("TestShort"short.MaxValue);
                    row.SetField("TestSingle"Single.MaxValue);
                    row.SetField("TestString", "asdasd");
                    dt.Rows.Add(row);
                }
                {
                    DataRow row = dt.NewRow();
                    row.SetField("TestInteger"DBNull.Value);
                    row.SetField("TestBoolean"DBNull.Value);
                    row.SetField("TestByte"DBNull.Value);
                    row.SetField("TestDate"DBNull.Value);
                    row.SetField("TestDecimal"DBNull.Value);
                    row.SetField("TestDouble"DBNull.Value);
                    row.SetField("TestLong"DBNull.Value);
                    row.SetField("TestShort"DBNull.Value);
                    row.SetField("TestSingle"DBNull.Value);
                    row.SetField("TestString"DBNull.Value);
                    dt.Rows.Add(row);
                }

                return dt;
            }

     

    Wednesday, January 26, 2011 2:48 AM
  • I too am getting this error (using VS2010 Professional)- has anyone found a solution?
    Thursday, February 24, 2011 1:06 PM
  • Seems that I have solved the problem adding a reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library"

    Hope this help

    Tix

    • Proposed as answer by Jordan B Tuesday, August 09, 2011 11:24 PM
    • Marked as answer by Mike FengModerator Friday, October 07, 2011 6:10 AM
    Wednesday, April 27, 2011 12:30 PM
  • So it sounds like there are two answers here:

    When using Visual Studio 2010 , you can change the Target .NET Framework of your project from ".NET Framework 4.0" to ".NET Framework 3.5"

    or ".NET Framework 3.5 Client Profile"

    Or you can do as tix61 suggests and change your reference to "Microsoft ActiveX Data Objects Recordet 2.8 Library" instead of "Microsoft ActiveX Data Objects 2.8 Library"

    • Proposed as answer by Jordan B Tuesday, August 09, 2011 11:24 PM
    • Marked as answer by Mike FengModerator Friday, October 07, 2011 6:10 AM
    Tuesday, August 09, 2011 11:23 PM
  • When you try to add "Microsoft Active Data Objects Recordset 2.8 Library", right-click "Add Reference" in the project in VS 2010, in the "COM" tab, you can find "Microsoft Active Data Objects Recordset 2.8 Library"
    Thursday, March 22, 2012 5:20 AM
  • I had this problem, and I solved by change all references to "Microsoft Active Data Objects  2.6 Library". Before I have tried with 2.8 and 6.0, but I only had problems. 
    I only had this need of use ADODB, because I'm puting some reports used in VB 6.0 made with Seagate Crystal 6.0, and because these reports are very complex and to do again would make i lose a lot of time.

    I not recomend using of ADODB, only in cases like this, to avoid a lot of rework, but in all other situations I using Datatable (ADO.NET). Same in this project where I used some of old reports, I used ADO.NET in all other places, the only exception when print these old reports.

    Now these old reports are working perfectly on C# using also Seagate Crystal 6.0.

    Thursday, January 03, 2013 9:43 PM