Making my own database??

Hi!

I've been here a week or two ago trying to understand how to save text from edit box entries.  I found this to be lacking in security, to be honest, so I decided to create by Diary app as a Database.  So, first I'll briefly explain what I'm wanting to do, then I'll ask the question.

I'm working on a Diary application in VC++ 5 Pro. I need to create a database that will take entries from the program's edit box (as entry field) and save it to a database. Now, I have no idea if I can use the tables and MDB's already on my hard drive within the program, but I assume not.  I'm betting I have to create my own tables and database to include in this app.  So, since I do not have Access or any other Database creation software, I need to know, in detail, how to create the database I need - then I have to include it using AppWizard.

So, please, in detail, help me from start to finish with creating the database that will do the job I need to have a viable, working Daily Diary application. I also have VBasic on my system, as I hear it may be easier to create MDB's for DevStudio usage thru it. Can anyone please assist me?

I know this will be long and hard (I think), so I'm handing over all my points for this one.  Thanks!

Mike Wonch
MWonchAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

piano_boxerCommented:
Here is how you can create and 'format' a Access
database at runtime.

--------------

// Insert this code in some .CPP file

typedef struct
{
    LPCTSTR     lpszName;
    short       nType;
    long        lSize;
    long        lAttributes;
    BOOL        bRequired;
    BOOL        bAllowZeroLength;
} MY_FIELD_DEF;


// Static information about the fields that you want to create in
// the database table 'TestTable'

MY_FIELD_DEF my_fields[] = {
// FIELD 1
    "id",
    dbLong,
    0, // Dont matter here because dbLong is allways 4 bytes.
    dbUpdatableField | dbAutoIncrField,
    TRUE,
    FALSE,
// FIELD 2
    "text1",
    dbText,
    16,     // Max length of text (excluding zero-terminator!)
    dbUpdatableField,
    FALSE,  // Field not required!
    TRUE,   // Allow this string-field to be  'Not having a value'.
// FIELD 3
    "text2",
    dbText,
    32,     // Max length of text (excluding zero-terminator!)
    dbUpdatableField,
    FALSE,  // Field not required!
    TRUE,   // Allow this string-field to be  'Not having a value'.
};


BOOL CSomeClass::InitDB()
{
    // First, you need to determine if the database all-ready
    // exists, and if not create the actual database file.
    // I'll call it 'test.mdb'.

    if(!_access("test.mdb",0))
        return TRUE;

    CDaoDatabase db;

    try
    {
        db.Create("test.mdb");
    }
    catch(CException* p)
    {
        // Something went wrong!
        // Report error to user and make sure that the database
        // file is deleted.
        p->ReportError();
        p->Delete();
        DeleteFile("test.mdb");
        return FALSE;
    }

    // Database file is now created and opened
    // Now, create all the fields we requere.

    CDaoTableDef    table(&db);


    // Create all fields defined in static array 'my_fields'
    try
    {
        // First create the table called 'TestTable'
        //
        table.Create("TestTable");
        TRACE("'TestTable' created.\n");

        for(int i=0;i<sizeof(my_fields)/sizeof(my_fields[0]);i++)
        {
            table.CreateField(
                my_fields[i].strName,
                my_fields[i].nType,
                my_fields[i].lSize,
                my_fields[i].lAttributes );
   
            TRACE("Field '%s' created in 'TestTable'.\n", my_fields[i].strName);
   
        }

        // Append table to database collection and
        // close the tabledef recordset
        table.Append();
        table.Close();
    }
    catch(CException* p)
    {
        // Field creation failed
        // Report error to user, close database and
        // delete invalid database-file.
        p->ReportError();
        p->Delete();

        dc.Close();
        DeleteFile("test.mdb");
        return FALSE;
    }

    db.Close();

    // Table and fields was created successfully!
    return TRUE;
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MWonchAuthor Commented:
Excellent! Now, aside from the comments, this seems to create three fields when I only need one.  Is that so? If not, then ignore this and please accept my thanks! If yes, can I leave two out in favor of only one?

Mike Wonch
0
piano_boxerCommented:
Yes I create 3 fields in the example.

Look at the my_fields[] static structure. This is defined to have 3 fields ( // FIELD 1, // FIELD 2, // FIELD 3 ). Just change it to something like this (only one field):


// Static information about the fields that you want to create in
// the database table 'TestTable'

MY_FIELD_DEF my_fields[] = {
    "text1",
    dbText,
    16,     // Max length of text (excluding zero-terminator!)
    dbUpdatableField,
    FALSE,  // Field not required!
    TRUE,   // Allow this string-field to be  'Not having a value'.
};


0
MWonchAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.