hello!
I wan't to connect VC++ with Access 2000, how can i proceed?
thanks!
Printable View
hello!
I wan't to connect VC++ with Access 2000, how can i proceed?
thanks!
U can use ODBC/DAO/ADO to read and write data to different databases, but corresponding database drivers should be there. Say if u are using DAO u can use the classes like CDaoDatabase,CDaoRecordset,CDaoTabledef etc to do that.
This is a sample code which will create an MDB(MS-Access file) for you:
===
CDaoDatabase db;
db.Create("c:\\test.mdb",dbLangGeneral,dbVersion30);
CDaoTableDef td(&db);
td.Create("Employee");
td.CreateField( "BookNo", dbLong,4,dbLong);
td.CreateField( "EmpName", dbText,255,dbVariableField);
td.Append();
CDaoRecordset rs(&db);
rs.Open(&td,dbOpenDynaset);
if(rs.CanAppend())
{
rs.AddNew();
CString EmpName="S.K.Pradhan";
long slNo=100;
COleVariant bookNo(slNo);
rs.SetFieldValue("EmpName",(LPCSTR) EmpName);
rs.SetFieldValue("BookNo",bookNo);
rs.Update();
rs.AddNew();
bookNo.Clear();
}
rs.Close();
td.Close();
db.Close();
===
This is a sample code which reads an .MDB(Access file)
===
CDaoDatabase db;
db.Open("e:\\tmp\\student.mdb",FALSE,TRUE,_T(""));
int totTables=db.GetTableDefCount();
CDaoTableDef td(&db);
td.Open("BOOK");
CDaoRecordset rs(&db);
rs.Open(&td);
int reccount=rs.GetRecordCount();
COleVariant olv;
CString name;
for(int i=0;i<reccount;i++)
{
olv=rs.GetFieldValue("BOOKID");
name.Format("%d",olv.intVal);
AfxMessageBox(name);
rs.MoveNext();
}
db.Close();
===
Regards
S.K.Pradhan
Be sure to rate answers if it helped, to encourage them.
thank you for your response
the use of of CDao objects allow to connect to a Access97 database.
With these objects we can not use access2000 database.
and this is my pb.
MSDN has several articles on how to do this.
Search MSDN with keywords "Access 2000 VC++"
(Search "DAO 2000" was more productive. Sorry.)
Article Q236991 and Q230485