
Creating a Data Base in VC++
try{
// create the database
CDaoDatabase Database;
Database.Create( szDBName );
// create the table
CDaoTableDef Table(&Database);
Table.Create(szTableName );
// create 2 fields
Table.CreateField( "Field 1", dbText, 20);
Table.CreateField( "Field 2", dbMemo, 300);
Table.Append();
// create the record set
CDaoRecordset DaoRecordset;
DaoRecordset.Open(&Table);
// add a new record
DaoRecordset.AddNew();
DaoRecordset.SetFieldValue("Field 1", "value1 " );
DaoRecordset.SetFieldValue("Field 2", "value2 " );
DaoRecordset.Update();
DaoRecordset.Close();
Table.Close();
Database.Close();
Quote:
}
catch( CDaoException* pE )
{
pE->ReportError();
pE->Delete();
Quote:
}
Niall
Quote:
> Microsoft Press has a book, "Microsoft Jet Database Engine Programmer's
> Guide" with a CDROM that I found very helpful in getting code running to
> construct and access databases from VC++.
> --
> Eldon Ziegler
> HomAtion Systems
> http://www.homation.com
> > We need to create a data base under Visual C++ without a user
interface.
> > It should be a simple DB created from a file based on normal C
> structures,
> > such as: struct A { int x; int y; CString s; }; and it should be
created
> > from within the application itself and NOT via Microsoft Access.
> > We would like to be able to add records according to a specific key,
> > and then update them if necessary. From the help and examples we found
in
> > Books On Line, we couldn't make out how exactly to go about it in a
> dialog
> > based application ( no docs, no views, no nothing ).
> > Any help would be appreciated, especially if a small example comes with
> it.
> > --
> > ---Beware the Jabberwock, my son!---
> > ------Ian Kojurin-------