Connecting MS Access and Autocad C#

Connecting MS Access and Autocad C#

khalili_masoomeh
Enthusiast Enthusiast
1,762 Views
3 Replies
Message 1 of 4

Connecting MS Access and Autocad C#

khalili_masoomeh
Enthusiast
Enthusiast

Hello Everyone

I have a simple MS Access Table that includes a list of points , and then i want to write a code in C# to read that points from Access and Draw them in Autocad . is there anybody who knows how to write this code? (generally the question is about reading any data from MS Access and give it to Autocad by C# it may be point or line or something else but I think the points are the simplest case to learn)

 

Thanks in Advance.!

0 Likes
1,763 Views
3 Replies
Replies (3)
Message 2 of 4

norman.yuan
Mentor
Mentor

You use ADO.NET in .NET framework to access data stored in various database, including MS Access database (*.mdb/*.accdb). Note, it is not necessary to install MS Access itself, but you need to installed MS Access DB Engine (free download from MS site), if the computer does not have MS Access installed. However, since these days no one uses 32-bit AutoCAD, the MS Access db Engine must also be 64-bit. This may lead to problem: if the computer has MS Office suite, including MS Access, it is most likely 32-bit, then you cannot install 64-bit MS Access DB Engine. If the MS Office suite does not include MS Access, the 64-bit MS Access DB Engine can be installed if the MC Office is later version (at least Office 2013 or later). For earlier Office, installing 64-bit MS Access DB Engine could be very tricky, or not possible (when Office suite is too old, like 2005/2007). Also, the installation needs local admin privilege, this along makes thing unfavorable. Unless you have to use MS Access' UI to manage the data outside AutoCAD (especially you have already have MS Access application working on the data), choosing *.mdb/*.accdb to store data for AutoCAD's external data source is bad choice. Other choices of data storage include real database server (SqlServer/Express, MySql...), lightweight file-based Sql-lite, or even XML file. text file...

 

While you learn database programming with ADO.NET, you'd better off do it outside AutoCAD with an simple console EXE or Win Form EXE to save you from having to start time-consuming AutoCAD for debugging/testing. The data accessing code should be in a class library (DLL) project, referenced into the EXE; so later it can be referenced by your Acad add-in project to access data. There are huge amount of posts/sample code/tutorial video on ADO.NET online. Search the net and off you go.

 

If you do have experience/knowledge of data access programming, you might want to define a data access Interface, which sits between AutoCAD working code and real data source; so that AutoCAD only knows the interface and does not care where/how the data is stored (MS Access DB, SQLServer, or served from somewhere in the cloud), and you have different code to implement the interface according to the data storage/source. Not knowing your database programming knowledge level, I am not going to elaborate more.

 

 

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 4

khalili_masoomeh
Enthusiast
Enthusiast

Thank you for replying. 

I want to know How to write this code in C# . I didn't see any samples for it. 

0 Likes
Message 4 of 4

norman.yuan
Mentor
Mentor

You do not write C# (or VB.NET, for that matter) code to try to get data from MS Access (or any database) without knowing/learning the very basics of ADO.NET.

 

While I do not think it is good by directly jumping into ADO.NET sample code of accessing data in MS Access database without know the very ABC of ADO.NET, there is vast amount of information available online at your finger tips: just search the internet for "ADO.NET", or "ADO.NET & MS Access".  Such as:

 

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ado-net-code-examples 

https://www.c-sharpcorner.com/UploadFile/puranindia/ado-net-application-using-ms-access-2007-databas... 

 

There is also plenty of tutorials on YouTube. Simply search "ADO.NET Ms Access" would tons of videos for watch/learn for hours or days.

 

While these sample codes/tutorials have nothing to do with AutoCAD itself, they are what exactly you need to learn about ADO.NET for access data from database, inside/from AutoCAD or not.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes