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. Database Problem!

Database Problem!

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestionannouncement
3 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.
  • V Offline
    V Offline
    vcseeker
    wrote on last edited by
    #1

    Hi , I am trying to read some data from a tab delimited text file taking individual field values from text file and putting it into an access databse.I have 2 recordsets one that fetches data from Text file and the other is that inserts the values into the data base.The code after opening the recordset successfully is something like this. if(rs.IsBOF()) return false; rs.MoveFirst();//rs IS THE RECORDSET THAT FETCHES RECORDS FROM DATA FILES while(!rs.IsEOF()) { recset.AddNew();///recset IS THE RECORDSET THAT FETCHES RECORDS FROM DATAFILES recset.m_A = rs.m_A; recset.m_R = rs.m_R; recset.m_Absolute = rs.m_Absolute; recset.m_Relative = rs.m_Relative; recset.m_Class = rs.m_Class; // recset.m_Azimuth = rs.m_Azimuth; // recset.m_Int = rs.m_Int; //recset.m_Box =rs.m_Box; recset.m_2002D = rs.m_2002D; recset.m_2002H = rs.m_2002H; recset.m_1993D = rs.m_1993D; recset.m_1993H = rs.m_1993H; recset.m_Growth = rs.m_TXT_Growth; recset.m_Growth2 = rs.m_TXT_Growth2; recset.m_Growth3 = rs.m_TXT_Growth3; recset.m_Wt = rs.m_Wt; //recset.m_Comment = recset.m_Comment; if(!recset.Update( )){ AfxMessageBox("Record not added."); return FALSE; } rs.MoveNext(); } My problem is that some members like m_azimuth(type-CTime) and m_Int,m_Box(type-CString) are not being copied to access recordset and not being updated to Access and Update function is unsuccessful.all other members are numbers and they don't have any problem copying.One CString object m_class is being copied without any problem. The commented code shown above is working well ,but if i uncomment these portions Update function fails,Can nebody tell me what may be the problem?

    T 1 Reply Last reply
    0
    • V vcseeker

      Hi , I am trying to read some data from a tab delimited text file taking individual field values from text file and putting it into an access databse.I have 2 recordsets one that fetches data from Text file and the other is that inserts the values into the data base.The code after opening the recordset successfully is something like this. if(rs.IsBOF()) return false; rs.MoveFirst();//rs IS THE RECORDSET THAT FETCHES RECORDS FROM DATA FILES while(!rs.IsEOF()) { recset.AddNew();///recset IS THE RECORDSET THAT FETCHES RECORDS FROM DATAFILES recset.m_A = rs.m_A; recset.m_R = rs.m_R; recset.m_Absolute = rs.m_Absolute; recset.m_Relative = rs.m_Relative; recset.m_Class = rs.m_Class; // recset.m_Azimuth = rs.m_Azimuth; // recset.m_Int = rs.m_Int; //recset.m_Box =rs.m_Box; recset.m_2002D = rs.m_2002D; recset.m_2002H = rs.m_2002H; recset.m_1993D = rs.m_1993D; recset.m_1993H = rs.m_1993H; recset.m_Growth = rs.m_TXT_Growth; recset.m_Growth2 = rs.m_TXT_Growth2; recset.m_Growth3 = rs.m_TXT_Growth3; recset.m_Wt = rs.m_Wt; //recset.m_Comment = recset.m_Comment; if(!recset.Update( )){ AfxMessageBox("Record not added."); return FALSE; } rs.MoveNext(); } My problem is that some members like m_azimuth(type-CTime) and m_Int,m_Box(type-CString) are not being copied to access recordset and not being updated to Access and Update function is unsuccessful.all other members are numbers and they don't have any problem copying.One CString object m_class is being copied without any problem. The commented code shown above is working well ,but if i uncomment these portions Update function fails,Can nebody tell me what may be the problem?

      T Offline
      T Offline
      Toni78
      wrote on last edited by
      #2

      I don't use CRecordset class but I use ADO recordset and I had the exact same problem that you are describing. My problem was that the fields that I was updating were set to null, so I had to go and change their status flag manually to "Field OK". The problem was that every new row that you add to your database has to have values that are initialized to some acceptable value. For strings for example it would be a good idea to initialize them to a space " ". Let's say that you have a table with three fields: fieldInt | fieldDbl | fieldStr | When you want to add a new row to this table you should initialize these fields first. recordset.fieldInt = 0; recordset.fieldDbl = 0; recordset.fieldStr = " "; // Then do some stuff like changing the values of these fields with the data that you get from the file. recordset.AddNew(); I hope you understood this confusing description. And by the way, I looked at CRecordset class and probably you should call the function IsFieldNull() to check the fields. // Afterall I realized that even my comment lines have bugs

      B 1 Reply Last reply
      0
      • T Toni78

        I don't use CRecordset class but I use ADO recordset and I had the exact same problem that you are describing. My problem was that the fields that I was updating were set to null, so I had to go and change their status flag manually to "Field OK". The problem was that every new row that you add to your database has to have values that are initialized to some acceptable value. For strings for example it would be a good idea to initialize them to a space " ". Let's say that you have a table with three fields: fieldInt | fieldDbl | fieldStr | When you want to add a new row to this table you should initialize these fields first. recordset.fieldInt = 0; recordset.fieldDbl = 0; recordset.fieldStr = " "; // Then do some stuff like changing the values of these fields with the data that you get from the file. recordset.AddNew(); I hope you understood this confusing description. And by the way, I looked at CRecordset class and probably you should call the function IsFieldNull() to check the fields. // Afterall I realized that even my comment lines have bugs

        B Offline
        B Offline
        basementman
        wrote on last edited by
        #3

        I have found that the MFC database classes SUCK. You may be better off doing one of the following: 1) If the name of your text file doesn't change, create a Linked Table in access to your text file. Then, you can use access insert/select statements to copy the data. -or- 2) build your own insert statement from the retrieved data and execute it against access, rather than using all of the overhead crap of CRecordSet. onwards and upwards...

        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