Difference between revisions of "MS Access"

From Lazarus wiki
Line 142: Line 142:
Working Source code sample:
Working Source code sample:(Updated with real coding)
Enjoy Lazarus
Enjoy Lazarus

Revision as of 03:25, 19 October 2010

This page explains how to use a Microsoft Access database.

Databases portal


Tutorials/practical articles:


Advantage - MySQL - MSSQL - Postgres - Interbase - Firebird - Oracle - ODBC - Paradox - SQLite - dBASE - MS Access - Zeos


Goto your [Data sources (ODBC)] at the control panel administrative tools. Goto [File DSN] tab menu, Click Add, then Select <microsoft access driver>, Next, Browse a path TO save your .DSN file, because that dsn file will contain the configuration where you store your database file(.mdb). Click Next, then Finish(you have created a new .dsn file) of which will be use in your TODBCConnection [FileDSN]. Save the .dsn in your current project path.

at your Lazarus form Drop: TSQLQuery TSQLTransaction TODBCConnection TDatasource TDBGrid

at TOBDCConnection Properties; Set; FileDSN : thepathofyour.dns_saved\the.dsn_filesaved eq., c:\mylazarus\project1\myFile.dsn then Set; Transaction: SQLTransaction1 Set; Username: admin Set; Connected: True; Do not put any other entries in the properties. (just that)

at TSQLTransaction Properties; Set; Database: ODBCConnection1 Set; Active: True

at TDatasource Properties; Set; DataSet: SQLQuery1

at TSQLQuery1 Properties; Set; Database: ODBCConnection1 Set; SQL: select * from TABLEyouknow Set; Active: True

at TDBGrid Properties; Set; Datasource: Datasource1

You will noticed an active data inside DBGrid.

Your '''FILE.dsn''' may contain like this.......... [ODBC] DRIVER=Microsoft Access Driver (*.mdb) UID=admin UserCommitSync=Yes Threads=3 SafeTransactions=0 PageTimeout=5 MaxScanRows=8 MaxBufferSize=2048 FIL=MS Access DriverId=25 DefaultDir= DBQ=msaccess.mdb

Important: .dsn file is inside your current project application path. Unlike [System DSN] or [User DSN], they are configured by [ODBC Data Source Administrator] inside your system and '''cannot fly''',

BUT using FILE dsn? You can manage to edit each line as long as you understand it, and is a portable file in which you can fly anywhere.

File DSN

A file DSN is simply where the connection settings are written to a file. The reason for having a file DSN is if you want to distribute a data source connection to multiple users on different systems without having to configure a DSN for each system. For instance, I can create a file DSN to a reporting database on my desktop. I can then send the file to my users. My users can save the file DSN to their hard drives and then point their reporting applications at the file DSN.

Go and tell others about Lazarus.

But if FILE DSN won't work on you, try using SYSTEM DSN, and type at TODBCConnection Set; DatabaseName: yourSYSTEMDNS_ADDED

if USER dsn, SYSTEM dsn, FILE dsn wont work?

at SQLQuery1 Properties Set; UsePrimaryKeyAsKey: False


Roca Robin

Working Source code sample:(Updated with real coding) http://www.mediafire.com/file/8dbc13jaj8twu89/msaccestest.zip

Enjoy Lazarus