Solved

Making my own database??

Posted on 1998-06-08
4
171 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:MWonch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
piano_boxer earned 130 total points
ID: 1316263
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
 

Author Comment

by:MWonch
ID: 1316264
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
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1316265
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
 

Author Comment

by:MWonch
ID: 1316266
Thanks!
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question