CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2013
    Posts
    3

    Getting error while retrieving value from ADO recordset.

    I have a vc++ project file which reads data from access 2007 database.

    I have successfully declared and opened connectionPtr and recordSetPtr objects.

    The follwoing code is giving an error message that "item cannot be found in the collection"
    stringVar = (recordSet->Fields->GetItem("[String]")->GetValue()).bstrVal;

    If i replace "[String]" with "String" then above statement executed successfully.

    How can i execute the above statement with "[String]" without errors?


    Thanks in advance.

    Regards,
    Siva.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Getting error while retrieving value from ADO recordset.

    I guess that ADO itself passes the item name in correct format as well as you have passed it as text (using quotation marks)
    The same is true if you would pass item name within apostrophes in some SQL statement: brackets were not only not needed but also were erroneous!
    Victor Nijegorodov

  3. #3
    Join Date
    Jul 2013
    Posts
    3

    Re: Getting error while retrieving value from ADO recordset.

    Thanks Victor for responding to this.
    I am in a situation where i can not remove square brackets[]. How do i proceed in this situation. Any suggestions?

    What i am planning is that, First i will identify whether the field name contains square backets through code and then remove it(square bracket) if it exists. Is it right approach?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Getting error while retrieving value from ADO recordset.

    Quote Originally Posted by sankar540 View Post
    I am in a situation where i can not remove square brackets[].
    Why?

    Quote Originally Posted by sankar540 View Post
    What i am planning is that, First i will identify whether the field name contains square backets through code and then remove it(square bracket) if it exists. Is it right approach?
    It sounds reasonable.
    Victor Nijegorodov

  5. #5
    Join Date
    Jul 2013
    Posts
    3

    Re: Getting error while retrieving value from ADO recordset.

    The reason for the situation where i can not remove square brackets is as follows.
    Generally we get database(Access) from customer. That database contains 2 tables say table1 and table2.
    One of the fields name in Table1 is "StringFieldName". The values for this fields would be like [a],[b],[c]......

    Now the field names for Table2 should be the unique values of Table1's "StringFieldName" field. that means in this scenario the fields names for Table2 should be a,bc,c...

    What we do is we read Table1's "StringFieldName" field value based on some criteria and identify whether it is a,b or c. If it is [a] then we fetch value from Table2's of [a] field.
    As of now we did not face any problem as we are using DAO. Now we are moving to ADO and start facing problem with square brackets.


    Thanks & Regards,
    Siva.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured