Connection to external Databases via ODBC / ADO

Christian_Buehl
Member Posts: 145
Connect external databases (Access, ODBC-Databases etc) via ADODB.
Hope this is useful for the community.
Other Databases should work with just a different connection string
Hope this is useful for the community.
Other Databases should work with just a different connection string
Example for ADO-Access on external ODBC-Database ADOConn Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Connection ADOrs Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Recordset ConnStr Text 200 AnzCount Text 30 OpenMethod Integer LockMethod Integer Name Text 200 Str Text 200 // Test ODBC-Connector OpenMethod := 2; // 1=adOpenKeyset; 2=adOpenDynamic; 3= adOpenStatic LockMethod := 3; // 1=dLockreadonly; 2=adLockPessimistic; 3=adLockOptimistic; 4=adLockBatchOptimistic CREATE(ADOconn); ConnStr := 'PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=D:\TestDB.mdb'; ADOconn.Open(ConnStr); CREATE(ADOrs); ADOrs.Open('Select Name,Street from T1',ADOconn,OpenMethod,LockMethod); ADOrs.MoveFirst; Name := ADOrs.Fields.Item('Name').Value; Str := ADOrs.Fields.Item('Street').Value; // MESSAGE('Name %1 - Street %2', Name, Str); ADOrs.MoveNext; Name := ADOrs.Fields.Item('Name').Value; Str := ADOrs.Fields.Item('Street').Value; // MESSAGE('Name %1 - Strasse %2', Name, Str); // Update current data ADOrs.Update('Street','Testroad'); ADOrs.Update('Name','Anyone'); // Insert new Data ADOrs.AddNew; ADOrs.Update('Strasse','New Street Text'); ADOrs.Update('Name','New name'); ADOrs.Close; ADOconn.Close; CLEAR(ADOrs); CLEAR(ADOconn);
0
Comments
-
I would like to see if anyone has a way of reading NULL values from a db that allows nulls. I cannot test for NULL in Navision, so this ADO method presents quite a problem if you have nullable fields in the db to read from.
In the past I have created a wrapper for the ADO obs, in my own OCX where i return a text value (VB pseudo code - below),
if isnull(rs.field("Field1").value) then
FieldValue = ""
else
FieldVale = rs.field("Field1").value0 -
Hi
You can try to replace the null value inside the select command. I guess, somethin like this should do the trick on sql server.
SELECT code, name,
COALESCE(address, '')
FROM myTable
Regards
H0 -
hi, this is what i used:
Field.ActualSize
Syntax
put Field.ActualSize
Returns
Integer
value that indicates the actual length of a field's value.
Description
Returns the ActualSize property of the wrapped ADODB.Field object. Use the ActualSize property to return the actual length of a Field object's value. If ADO cannot determine the length of the Field object's value, the ActualSize property returns -1.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions