Solved

Making my own database??

Posted on 1998-06-08
4
170 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 76
MaxSpan challenge 9 140
Is there a simple front-end menu system. 9 147
Work with App store 7 122
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

751 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