Jump to content
dzul89

Link C++ Ke Microsoft Access

Recommended Posts

Assalammualaikum dan salam sejahtera kepada semua ... saya nak minta tolong mcm mane nak link kan C++ ke Microsoft Access ??? bleh x ?? tolong bagi coding yg nak buat link dia . please tolong

Share this post


Link to post
Share on other sites

Microsoft Access adalah applikasi daripada Microsoft. Kita tak boleh 'link' terus kepada MS Access. Apa yang kita boleh buat adalah link kepada JET engine atau ODBC utk mengakses ke fail databasenya. Ala... yang *.mdb tu.

Microsoft Access menggunakan JET engine utk mengakses databasenya. camni

MS Access -----> JET Engine ------> C:\Documents\[filename].mdb

Jadi kita terus direct ke JET engine dia

C++ App ------> JET Engine ------> C:\Documents\[filename].mdb

Ataupun guna ODBC engine utk aksess database

C++ App ------> ODBC ------> C:\Documents\[filename].mdb

Cara sebenar untuk 'link' bergantung kepada library C++ yang digunakan. Contohnya:-

Dengan library MFC + ODBC..

CDatabase db;
db.Open("[Path to file]");
CRecordset rs( &db );
rs.Open("Select...... From....");
while (!rs.EOF())
 ........ 
rs.Close();
db.Close();
Atau guna MFC + DAO
CDaoDatabase db;
db.Open("[Path to mdb file]");
CDaoRecordset rs( &db );
rs.Open("Select...... From....");
while (!rs.EOF())
 ........ 
rs.Close();
db.Close();
DAO akan menggunakan JET engine utk akses ke Microsoft Access database file (*.mdb). Kalau suka dengan sintaks C++ Standard Library, bolehla guna OTL + ODBC
otl_connect db; // connect object
otl_connect::otl_initialize(); // initialize ODBC environment

db.rlogon("[Path to mdb file (*.mdb)]"); 
otl_stream i (50,  "select ... from .... ",  db); 

int f1;

while(!i.eof())
{ 
  i>>f1; //baca nilai dari database
  cout << f1 << endl; //papar nilai ke console
}
  db.logoff();

Ada banyak lagi database library yang kita boleh guna macam Ole DB dan SOCI. Tapi semuanya bergantung kepada citarasa masing masing.

Share this post


Link to post
Share on other sites

pada pendapat aku, elok una ADO drpd DAO sbb DAO da obsolete :ph34r:

kalu guna ADO, langkah2 basic ialah:

- import ADO library :

#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
        rename_namespace("ADOku") rename("EOF","eofile")
using namespace ADOku;
EOF tu kena rename utk mengelakkan confilct dikemudian hari... namespace tu biasa kita renamekan supaya sng... - initialize COM bila nk guna dan uninitialize COM bila da tanak guna kita :
::CoInitialize(NULL); //utk initalize
::CoUninitialize(); //utk uninitialize
- buat connection ngan database kita:
_ConnectionPtr pConn; //declare connection pointer kita
pConn.CreateInstance( __uuidof(Connection)); //buat instance utk connection tu

//open connection tu guna jetOLE 
//(-1 kat blkg tu menunjukk cursor type kita jenis adOpenUnspecified...
//utk malumat lanjut, sila google :D)
pConn->Open(L"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\folderKu\\dbKu.mdb",L"",L"",-1);
- manipulasikan data menggunakan recordset pointer:
_RecordsetPtr pRst;
pRst.CreateInstance(__uuidof(Recordset));

//cth: buka sumer field dr tableKu
pRst->Open("SELECT * FROM tableKu", pRst.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);

-biasakan dgn SQL...byk pekdahnya :D...

try cari tutorial online pasal ni...pastu try wat satu simple program...

kalu ada maslah mana2, bole dtg tanya :D...

Share this post


Link to post
Share on other sites

erk... konsep die same ke mcm link kan website dgn MySQL

sbb kalo dibace sekali imbas camtuh la gamaknye....

wats da difference pkai access dgn notepad tuh... alla... yg biase kite wat utk projek tuh...

Share this post


Link to post
Share on other sites

erk... konsep die same ke mcm link kan website dgn MySQL

sbb kalo dibace sekali imbas camtuh la gamaknye....

wats da difference pkai access dgn notepad tuh... alla... yg biase kite wat utk projek tuh...

yup!...konsep database mmg lebih kurang je...

bergantung atas provider...

guna notepad?...file streaming ke?...krg paham :D

Share this post


Link to post
Share on other sites

guna notepad?...file streaming ke?...krg paham

gituh la maksud ku....

cuma terminology je aku da lupe....

aritu mse utk group project...

ak wat gak camtuh....

ade function tuh... cume x reti cmne nak ltak data tuh dlm notepad....

therefore, die ley simpan data terbru time tuh je...

tutup je... die valotile....

heran gak aku....

Share this post


Link to post
Share on other sites

gituh la maksud ku....

cuma terminology je aku da lupe....

aritu mse utk group project...

ak wat gak camtuh....

ade function tuh... cume x reti cmne nak ltak data tuh dlm notepad....

therefore, die ley simpan data terbru time tuh je...

tutup je... die valotile....

heran gak aku....

ko bukak sbg ios::app x?...kalu x, dia xkan append tp overwrite file tu dgn data baru...

//ni da lari topik ni...kang susah plak nk kejar blk :D...

Share this post


Link to post
Share on other sites

ko bukak sbg ios::app x?...kalu x, dia xkan append tp overwrite file tu dgn data baru...

eerrr... ntah, da x ingat sgt....

nak cek, coding tu dlm external ak... maleh eh nak carik.... da sepah2....

ios::app

rsenye mcm pertama kali nmpak cmni... bukan la kot....

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...