|
-
September 21st, 2001, 04:20 AM
#1
VC++ and Access2000
hello!
I wan't to connect VC++ with Access 2000, how can i proceed?
thanks!
-
September 21st, 2001, 04:39 AM
#2
Re: VC++ and Access2000
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.
-
September 21st, 2001, 05:30 AM
#3
Re: VC++ and Access2000
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.
-
September 21st, 2001, 09:04 AM
#4
Re: VC++ and Access2000
MSDN has several articles on how to do this.
Search MSDN with keywords "Access 2000 VC++"
-
September 21st, 2001, 09:09 AM
#5
Re: VC++ and Access2000
(Search "DAO 2000" was more productive. Sorry.)
Article Q236991 and Q230485
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|