Results 1 to 3 of 3

Thread: MS Access and Object data

  1. #1
    Member
    Join Date
    2005-08
    Posts
    2
    Login to Give a bone
    0

    Question MS Access and Object data

    Any idea how to import table structure from MS Access or MS SQL, and use this structure for Object data in Map, or how to import directly table definition to create the same table structure for Object data.

    Thanks

  2. #2
    Civil Engineering Moderator MHultgren's Avatar
    Join Date
    2000-12
    Location
    Central Iowa
    Posts
    1,431
    Login to Give a bone
    0

    Default Re: MS Access and Object data

    domagoj,

    Have you looked at the ATP course from last month on using Access and Map? You may be able to find it in the archives for last month still. This should help you tremendously. You can get there by clicking on the Education link in the header. Then click on ATP and browse the archives.
    Mark Hultgren
    Just a Lurker
    http://www.MKW-Ind.com
    Blog
    Socializing??

  3. #3
    Active Member
    Join Date
    2002-11
    Posts
    50
    Login to Give a bone
    0

    Default Re: MS Access and Object data

    I use John Fleming's ADO_Library.lsp as a starting point and go from there. It is freely available at http://www.fleming-group.com This is a straight plagerism from there to give you a list of all tables and their fields as a dotted list.

    Code:
     (defun get_tblfld (sourcedb /)
      (vl-load-com)
      (load (findfile "ADOLISP_Library.lsp"))
      (setq ConnectString
      (strcat "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
       sourcedb
       ";Persist Security Info=False"
      )
      )
      (if (not (setq ConnectionObject
    	(ADOLISP_ConnectToDB ConnectString "admin" "")
    	)
    	  )
    	(progn (prompt "\nConnection failed!")
    	(ADOLISP_ErrorPrinter)
    	)
      )
      (princ (ADOLISP_GetFieldsandTypes ConnectionObject))
      ;; Disconnect
      (prompt "\n\nDisconnecting from the database\n")
      (ADOLISP_DisconnectFromDB ConnectionObject)
      ;; Although the following is unnecessary in this case (because
      ;; ConnectionObject is a local variable), it's never a _bad_
      ;; idea to NIL-out the connection object.
      (setq ConnectionObject nil)
    )
    
    
    ;;; A function to obtain the names and data type of the fields
    ;;; in the tables in a database.
    ;;; Argument: ConnectionObject		 An ADO Connection Object
    ;; Return value:
    ;;;  A list of two lists.
    ;;;  The first list contains the field names.
    ;;;  The second list contains the data type.
    
    (defun ADOLISP_GetFieldsandTypes (ConnectionObject
    	  /	TempObject
    	  TempList   FieldsList
    	  TypesList   FieldNumber
    	  FieldCount
    	 )
      (setq ADOLISP_ErrorList  nil
     ADOLISP_LastSQLStatement nil
      )
      (setq RecordSetObject (vlax-create-object "ADODB.RecordSet"))
      ;; If we fail getting a recordset of the tables and views
      ;; ...
      (if (vl-catch-all-error-p
     (setq RecordSetObject
    		(vl-catch-all-apply
       'vlax-invoke-method
       (list
    	 ConnectionObject
    	 "OpenSchema"
    	 ADOConstant-adSchemaColumns
       )
    		)
     )
    	  )
    	;; Save the error information
    	(setq ADOLISP_ErrorList
    	(ADOLISP_ErrorProcessor RecordSetObject ConnectionObject)
    	)
    	(progn
    	  ;; Got the recordset!
    	  ;; We're about to get tricky, hang on!  Convert the
    	  ;; recordset object to a LISP list ...
    	  (setq
     TempList
      ;; Uses Douglas Wilson's elegant
      ;; list-transposing code from
      ;; http://xarch.tu-graz.ac.at/autocad/lisp/
      ;; to create the list of rows, because
      ;; GetRows returns items in column order
      (apply
    	'mapcar
    	(cons
    	  'list
    	  ;; Set up to convert a list of lists
    	  ;; of variants to a list of lists of
    	  ;; items that AutoLISP understands
    	  (mapcar
    		'(lambda (InputList)
    	(mapcar '(lambda (Item)
    		(ADOLISP_variant-value Item)
    	  )
    	 InputList
    	)
      )
    		;; Get the rows, converting them from
    		;; a variant to a safearray to a list
    		(vlax-safearray->list
       (vlax-variant-value
    	 (vlax-invoke-method
    	   RecordSetObject
    	   "GetRows"
    	   ADOConstant-adGetRowsRest
    	 )
       )
    		)
    	  )
    	)
      )
    	  )
    	  ;; end setq
    	  ;; Now filter out the system tables and
    	  ;; sort the tables and fields into the
    	  ;; correct lists
    	  (while (> (length TempList) 0)
     (setq TName (nth 2 (car TempList)))
     (foreach Item TempList
       (if (= (nth 2 Item) TName)
    	 (setq FieldsList (cons (vl-list* TName (nth 3 Item)) FieldsList)
    	TempList   (cdr TempList)
    	 )
    	 ;;end setq   
       )
       ;; end if
     )
     ;; end foreach
    	  )
    	  ;; end while
    	)
    	;; end progn
      )
      ;; end if
    
      ;; Close the recordset
      (vlax-invoke-method RecordSetObject "Close")
      (vlax-release-object RecordSetObject)
      ;; maybe also take out the system tables with vl-remove-if.
      (setq FieldsList (reverse FieldsList))
    )

Similar Threads

  1. 2014: Added object data fields to Polyline, but object data is empty or zero
    By tntdraftsol in forum AutoCAD Map 3D - General
    Replies: 6
    Last Post: 2015-07-24, 12:20 PM
  2. Access C3D Object Data in Fields
    By civil3d.wishlist1941 in forum Civil 3D Wish List
    Replies: 0
    Last Post: 2008-01-22, 04:45 PM
  3. Replies: 1
    Last Post: 2007-04-07, 12:39 PM
  4. How to Create Access table data to AutoCAD VBa Combo box data
    By avinash00002002 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2006-06-20, 08:22 PM
  5. Linking AutoCAD Object Data Table to Access table
    By m.storey in forum AutoCAD Map 3D - General
    Replies: 0
    Last Post: 2006-05-02, 02:54 PM

Posting Permissions

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