CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    3

    VC++ and Access2000

    hello!
    I wan't to connect VC++ with Access 2000, how can i proceed?
    thanks!


  2. #2
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    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.

  3. #3
    Join Date
    Sep 2001
    Posts
    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.



  4. #4
    Join Date
    Jan 2000
    Location
    San Diego, CA
    Posts
    1,334

    Re: VC++ and Access2000

    MSDN has several articles on how to do this.
    Search MSDN with keywords "Access 2000 VC++"


  5. #5
    Join Date
    Jan 2000
    Location
    San Diego, CA
    Posts
    1,334

    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
  •  





Click Here to Expand Forum to Full Width

Featured