Help with ADO Recordset Fields


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help with ADO Recordset Fields

  1. #1
    Marv Jones Guest

    Help with ADO Recordset Fields


    I am having a problem with using an index number to reference an ADO Field
    within a Recordset. The issue only surfaces under SQL Server 7; Access works
    fine with the code. The problem occurs when the Field name which the index
    references has an embedded blank space within it. The code which is causing
    me trouble is as follows:

    m_rstMealTotal.Fields(i).Value = rstMealCount.Fields(0).Value

    I have it in a loop cycling through meal names. This code runs fine as long
    as the m_rstMealTotal Field names are such as: "Breakfast", "Lunch", "Dinner",
    etc., i.e. names with no embedded space. It blows up when the field name
    becomes something like "Holiday Breakfast". This name, of course, contains
    an embedded space. The run-time error I am receiving is :
    Error code: -2147467259
    Error description: Line 1: Incorrect syntax near 'varchar'

    Has anyone else had a problem with indexes referencing field names with blank
    spaces? I am using VB 6.

    Thanks to anyone who can help.

    Marvin Jones

  2. #2
    Aleksandr Guest

    Re: Help with ADO Recordset Fields


    My suggestion is (I can't see this part of your code) to enclose the fieldnames
    in square brackets at recordset openning.
    Remember that you must avoid using SELECT *, so your select statement would
    be as follows:

    SELECT [BreakFast], [Holiday Breakfast] FROM Table WHERE Active = 1

    Hope it helps to you.
    Aleksandr

    "Marv Jones" <mjones@3gimax.com> wrote:
    >
    >I am having a problem with using an index number to reference an ADO Field
    >within a Recordset. The issue only surfaces under SQL Server 7; Access

    works
    >fine with the code. The problem occurs when the Field name which the index
    >references has an embedded blank space within it. The code which is causing
    >me trouble is as follows:
    >
    >m_rstMealTotal.Fields(i).Value = rstMealCount.Fields(0).Value
    >
    >I have it in a loop cycling through meal names. This code runs fine as

    long
    >as the m_rstMealTotal Field names are such as: "Breakfast", "Lunch", "Dinner",
    >etc., i.e. names with no embedded space. It blows up when the field name
    >becomes something like "Holiday Breakfast". This name, of course, contains
    >an embedded space. The run-time error I am receiving is :
    >Error code: -2147467259
    >Error description: Line 1: Incorrect syntax near 'varchar'
    >
    >Has anyone else had a problem with indexes referencing field names with

    blank
    >spaces? I am using VB 6.
    >
    >Thanks to anyone who can help.
    >
    >Marvin Jones



  3. #3
    Marv Jones Guest

    Re: Help with ADO Recordset Fields


    Thanks, Aleksandr,

    I need to get my field names from the table field names themselves. I guess
    I just need to know if what I am experiencing is a bug with ADO or not.
    I can't understand why it will let me use an index number as a field ordinal
    except when the Field name contains a blank space.

    I suppose I will keep on researching until I find an answer.

    Marv Jones
    "Aleksandr" <aca@mailops.com> wrote:
    >
    >My suggestion is (I can't see this part of your code) to enclose the fieldnames
    >in square brackets at recordset openning.
    >Remember that you must avoid using SELECT *, so your select statement would
    >be as follows:
    >
    >SELECT [BreakFast], [Holiday Breakfast] FROM Table WHERE Active = 1
    >
    >Hope it helps to you.
    >Aleksandr
    >
    >"Marv Jones" <mjones@3gimax.com> wrote:
    >>
    >>I am having a problem with using an index number to reference an ADO Field
    >>within a Recordset. The issue only surfaces under SQL Server 7; Access

    >works
    >>fine with the code. The problem occurs when the Field name which the index
    >>references has an embedded blank space within it. The code which is causing
    >>me trouble is as follows:
    >>
    >>m_rstMealTotal.Fields(i).Value = rstMealCount.Fields(0).Value
    >>
    >>I have it in a loop cycling through meal names. This code runs fine as

    >long
    >>as the m_rstMealTotal Field names are such as: "Breakfast", "Lunch", "Dinner",
    >>etc., i.e. names with no embedded space. It blows up when the field name
    >>becomes something like "Holiday Breakfast". This name, of course, contains
    >>an embedded space. The run-time error I am receiving is :
    >>Error code: -2147467259
    >>Error description: Line 1: Incorrect syntax near 'varchar'
    >>
    >>Has anyone else had a problem with indexes referencing field names with

    >blank
    >>spaces? I am using VB 6.
    >>
    >>Thanks to anyone who can help.
    >>
    >>Marvin Jones

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center