ADO Recordset error
davisj
Member Posts: 38
Hi All! I'm running into a bit of a problem when trying to use ADO to connect to another Navision Database. Here is my code...
CREATE(lADOConnection);
CREATE(lADORecordSet);
lADOConn.Open('Provider=SQLOLEDB.1;Password=xxxx;User ID=xxxx;Initial Catalog=MyDatabase;Data Source=MyServer);
lSQL:='SELECT [Scrap Mileage], [Scrap Count] FROM [Company$Manufacturing Setup]';
lADORecordset.Open(lSQL,lADOConnection);
lScrapCount:=lHTSMfgSetup.Fields.Item('[Scrap Count]').Value;
lScrapMileage:=lHTSMfgSetup.Fields.Item('[Scrap Mileage]').Value;
Here's the problem.... When the code gets to the line that is supposed to assign the recordset field value to my variable, I get the following error:
"The call to member Item Failed. ADODB Fields returned the following message: Item cannot be found in the collection corresponding to the requested name or ordinal"
I'm not sure why I'm getting this!!!! ](*,)
lADORecodset is defined as 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset, so I figure this should work fine.
Anyone run into this problem????
Thanks in advance
Jim
CREATE(lADOConnection);
CREATE(lADORecordSet);
lADOConn.Open('Provider=SQLOLEDB.1;Password=xxxx;User ID=xxxx;Initial Catalog=MyDatabase;Data Source=MyServer);
lSQL:='SELECT [Scrap Mileage], [Scrap Count] FROM [Company$Manufacturing Setup]';
lADORecordset.Open(lSQL,lADOConnection);
lScrapCount:=lHTSMfgSetup.Fields.Item('[Scrap Count]').Value;
lScrapMileage:=lHTSMfgSetup.Fields.Item('[Scrap Mileage]').Value;
Here's the problem.... When the code gets to the line that is supposed to assign the recordset field value to my variable, I get the following error:
"The call to member Item Failed. ADODB Fields returned the following message: Item cannot be found in the collection corresponding to the requested name or ordinal"
I'm not sure why I'm getting this!!!! ](*,)
lADORecodset is defined as 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset, so I figure this should work fine.
Anyone run into this problem????
Thanks in advance
Jim
0
Comments
-
...just a blindshot, try this:
lScrapCount:=lHTSMfgSetup.Fields.Item('Scrap Count').Value;--
Josef Snayberk0 -
Thanks for the suggestion.
It got me pointed in the right direction! Apparently, fields with spaces in them aren't liked by the ADO Recordset. So I ended up giving the field names aliases in my SQL Statement.
SELECT [Scrap Mileage] AS ScrapMileage, [Scrap Count] AS ScrapCount FROM [Manufacturing Setup]0 -
You might also try using 'CAST' in your SQL statement so that the Item property can refer to a "field" with no spaces. If you want to use spaces, I think you may have to use double quotes.0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions