Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing TEXT FILES into Access Tables

Changing TEXT FILES into Access Tables

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve Lai
    wrote on last edited by
    #1

    Hi everyone, I need help with converting Text Files into Access table and hope you can help me out. I have 2 TEXT FILES, first that contains the table name, and its attribues, and the SECOND file contains the values of the table. So if the first TEXT FILE that has the following table values: tablename field1, integer field2, string field3, integer field4, string then another TEXT FILE will contains the values for the table: 1, john, 6, smith 2, steve, 7, clark 3, carrie, 8, wayne 4, dan, 9, chait 5, erin, 10, alan what i need to do is to read the values from the FIRST TEXT FILE that contains the table attributes and create the table. Then i need to read the SECOND TEXT FILE and plug in the values. so at the end, i'll have a Access table like: field1 field2 field3 field4 1 john 6 smith 2 steve 7 clark 3 carrie 8 wayne 4 dan 9 chait 5 erin 10 alan But i need the readings of BOTH TEXT FILES to be dynamic so it'll work if the TEXT FILE has x number of columns, and x number of rows. and i also need the reading to be dynamic so it can read the values from the SECOND TEXT FILE no matter what kind of values it contains, ie, integer, string, char, etc... If anyone can help me out, Please let me know. Thanks in Advance. Steve

    P 1 Reply Last reply
    0
    • S Steve Lai

      Hi everyone, I need help with converting Text Files into Access table and hope you can help me out. I have 2 TEXT FILES, first that contains the table name, and its attribues, and the SECOND file contains the values of the table. So if the first TEXT FILE that has the following table values: tablename field1, integer field2, string field3, integer field4, string then another TEXT FILE will contains the values for the table: 1, john, 6, smith 2, steve, 7, clark 3, carrie, 8, wayne 4, dan, 9, chait 5, erin, 10, alan what i need to do is to read the values from the FIRST TEXT FILE that contains the table attributes and create the table. Then i need to read the SECOND TEXT FILE and plug in the values. so at the end, i'll have a Access table like: field1 field2 field3 field4 1 john 6 smith 2 steve 7 clark 3 carrie 8 wayne 4 dan 9 chait 5 erin 10 alan But i need the readings of BOTH TEXT FILES to be dynamic so it'll work if the TEXT FILE has x number of columns, and x number of rows. and i also need the reading to be dynamic so it can read the values from the SECOND TEXT FILE no matter what kind of values it contains, ie, integer, string, char, etc... If anyone can help me out, Please let me know. Thanks in Advance. Steve

      P Offline
      P Offline
      Philip Nicoletti
      wrote on last edited by
      #2

      Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :

      void get_field(void); // get the next field in the line
      // puts into variable : field
      // assumes that fields are separated
      // by commas

      add to the top of your .CPP file :

      #include <fstream.h> // for file i/o

      Add the following to the top of your .CPP file (or add as member variables in your .H file) :

      #define MAX_CHAR 80 // maximum number of characters per input line

      char field[MAX_CHAR]; // temporary, current field
      char tmp[MAX_CHAR]; // temporary, the entire line read in
      int start; // temporary, place to start looking for
      // the next field in the line

      #define MAX_FIELDS 20 // maximum number of fields

      int numFields; // actual number of fields

      CString tableName; // table name

      CString fieldName[MAX_FIELDS]; // names of the fields

      int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString

      Here is the code to read the first file, and determine the number of fields and the type of each field :

      // first ... read the definition file
      
      ifstream infile;
      infile.open("test1.txt");
      
      numFields = 0;
      
      infile.getline(tmp,MAX\_CHAR);
      start = 0;
      get\_field();
      tableName = field;
      
      
      while (!infile.eof())
      {
      	infile.getline(tmp,MAX\_CHAR);
      	if (infile.eof()) break;
      	start = 0;
      	get\_field();
      	fieldName\[numFields\] = field;
      
      	get\_field();
      	CString fieldType;
      
      	fieldType = field;
      	fieldType.MakeLower();
      	fieldType.TrimLeft();
      	fieldType.TrimRight();
      
      	if (fieldType == "integer") fieldCode\[numFields\] = 0;
      	if (fieldType == "float")   fieldCode\[numFields\] = 1;
      	if (fieldType == "string")  fieldCode\[numFields\] = 2;
      
      	numFields++;
      
      }
      infile.close();
      

      Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :

      // next ... read the value file
      // (open an output file to make sure we are reading correctly)
      
      infile.open("test2.txt");
      
      ofstream outfile;
      outfile.open("test3.txt");
      
      int num\_records = 0;
      
      while (!infile.eof())
      {
      
      S A 3 Replies Last reply
      0
      • P Philip Nicoletti

        Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :

        void get_field(void); // get the next field in the line
        // puts into variable : field
        // assumes that fields are separated
        // by commas

        add to the top of your .CPP file :

        #include <fstream.h> // for file i/o

        Add the following to the top of your .CPP file (or add as member variables in your .H file) :

        #define MAX_CHAR 80 // maximum number of characters per input line

        char field[MAX_CHAR]; // temporary, current field
        char tmp[MAX_CHAR]; // temporary, the entire line read in
        int start; // temporary, place to start looking for
        // the next field in the line

        #define MAX_FIELDS 20 // maximum number of fields

        int numFields; // actual number of fields

        CString tableName; // table name

        CString fieldName[MAX_FIELDS]; // names of the fields

        int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString

        Here is the code to read the first file, and determine the number of fields and the type of each field :

        // first ... read the definition file
        
        ifstream infile;
        infile.open("test1.txt");
        
        numFields = 0;
        
        infile.getline(tmp,MAX\_CHAR);
        start = 0;
        get\_field();
        tableName = field;
        
        
        while (!infile.eof())
        {
        	infile.getline(tmp,MAX\_CHAR);
        	if (infile.eof()) break;
        	start = 0;
        	get\_field();
        	fieldName\[numFields\] = field;
        
        	get\_field();
        	CString fieldType;
        
        	fieldType = field;
        	fieldType.MakeLower();
        	fieldType.TrimLeft();
        	fieldType.TrimRight();
        
        	if (fieldType == "integer") fieldCode\[numFields\] = 0;
        	if (fieldType == "float")   fieldCode\[numFields\] = 1;
        	if (fieldType == "string")  fieldCode\[numFields\] = 2;
        
        	numFields++;
        
        }
        infile.close();
        

        Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :

        // next ... read the value file
        // (open an output file to make sure we are reading correctly)
        
        infile.open("test2.txt");
        
        ofstream outfile;
        outfile.open("test3.txt");
        
        int num\_records = 0;
        
        while (!infile.eof())
        {
        
        S Offline
        S Offline
        Steve Lai
        wrote on last edited by
        #3

        Thanks Phil!

        1 Reply Last reply
        0
        • P Philip Nicoletti

          Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :

          void get_field(void); // get the next field in the line
          // puts into variable : field
          // assumes that fields are separated
          // by commas

          add to the top of your .CPP file :

          #include <fstream.h> // for file i/o

          Add the following to the top of your .CPP file (or add as member variables in your .H file) :

          #define MAX_CHAR 80 // maximum number of characters per input line

          char field[MAX_CHAR]; // temporary, current field
          char tmp[MAX_CHAR]; // temporary, the entire line read in
          int start; // temporary, place to start looking for
          // the next field in the line

          #define MAX_FIELDS 20 // maximum number of fields

          int numFields; // actual number of fields

          CString tableName; // table name

          CString fieldName[MAX_FIELDS]; // names of the fields

          int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString

          Here is the code to read the first file, and determine the number of fields and the type of each field :

          // first ... read the definition file
          
          ifstream infile;
          infile.open("test1.txt");
          
          numFields = 0;
          
          infile.getline(tmp,MAX\_CHAR);
          start = 0;
          get\_field();
          tableName = field;
          
          
          while (!infile.eof())
          {
          	infile.getline(tmp,MAX\_CHAR);
          	if (infile.eof()) break;
          	start = 0;
          	get\_field();
          	fieldName\[numFields\] = field;
          
          	get\_field();
          	CString fieldType;
          
          	fieldType = field;
          	fieldType.MakeLower();
          	fieldType.TrimLeft();
          	fieldType.TrimRight();
          
          	if (fieldType == "integer") fieldCode\[numFields\] = 0;
          	if (fieldType == "float")   fieldCode\[numFields\] = 1;
          	if (fieldType == "string")  fieldCode\[numFields\] = 2;
          
          	numFields++;
          
          }
          infile.close();
          

          Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :

          // next ... read the value file
          // (open an output file to make sure we are reading correctly)
          
          infile.open("test2.txt");
          
          ofstream outfile;
          outfile.open("test3.txt");
          
          int num\_records = 0;
          
          while (!infile.eof())
          {
          
          S Offline
          S Offline
          Steve Lai
          wrote on last edited by
          #4

          Thanks Phil! Does anyone else know how to solve this problem with the database part?

          1 Reply Last reply
          0
          • P Philip Nicoletti

            Here is some code to read the files ... I don't know anything about creating the access database though. first in your header file, add the member function :

            void get_field(void); // get the next field in the line
            // puts into variable : field
            // assumes that fields are separated
            // by commas

            add to the top of your .CPP file :

            #include <fstream.h> // for file i/o

            Add the following to the top of your .CPP file (or add as member variables in your .H file) :

            #define MAX_CHAR 80 // maximum number of characters per input line

            char field[MAX_CHAR]; // temporary, current field
            char tmp[MAX_CHAR]; // temporary, the entire line read in
            int start; // temporary, place to start looking for
            // the next field in the line

            #define MAX_FIELDS 20 // maximum number of fields

            int numFields; // actual number of fields

            CString tableName; // table name

            CString fieldName[MAX_FIELDS]; // names of the fields

            int fieldCode[MAX_FIELDS]; // 0 = int 1 = float 2 = CString

            Here is the code to read the first file, and determine the number of fields and the type of each field :

            // first ... read the definition file
            
            ifstream infile;
            infile.open("test1.txt");
            
            numFields = 0;
            
            infile.getline(tmp,MAX\_CHAR);
            start = 0;
            get\_field();
            tableName = field;
            
            
            while (!infile.eof())
            {
            	infile.getline(tmp,MAX\_CHAR);
            	if (infile.eof()) break;
            	start = 0;
            	get\_field();
            	fieldName\[numFields\] = field;
            
            	get\_field();
            	CString fieldType;
            
            	fieldType = field;
            	fieldType.MakeLower();
            	fieldType.TrimLeft();
            	fieldType.TrimRight();
            
            	if (fieldType == "integer") fieldCode\[numFields\] = 0;
            	if (fieldType == "float")   fieldCode\[numFields\] = 1;
            	if (fieldType == "string")  fieldCode\[numFields\] = 2;
            
            	numFields++;
            
            }
            infile.close();
            

            Here is the code to read the second file, and determines the value of each field for each record. Write out to a third file to make sure that everything is correct :

            // next ... read the value file
            // (open an output file to make sure we are reading correctly)
            
            infile.open("test2.txt");
            
            ofstream outfile;
            outfile.open("test3.txt");
            
            int num\_records = 0;
            
            while (!infile.eof())
            {
            
            A Offline
            A Offline
            Andre Dewispelaere 0
            wrote on last edited by
            #5

            I suggest to consult the book Inside Visual C++ by Kruglinsky. In this book the basics of ODBC an DAO acces is dealt with.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups