MS Access

From Lazarus wiki
Revision as of 16:26, 18 October 2010 by Sekelsenmat (talk | contribs)

This page explains how to use a Microsoft Access database.

Databases portal

References:

Tutorials/practical articles:

Databases

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

Instructions

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. Go and tell others about Lazarus. Regards, Roca Robin