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