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.
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!
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?
Re: Getting error while retrieving value from ADO recordset.
Quote:
Originally Posted by
sankar540
I am in a situation where i can not remove square brackets[].
Why?
Quote:
Originally Posted by
sankar540
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.
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.