|
-
March 24th, 2003, 07:08 PM
#1
GetFieldValue Twice
Hello,
I'm encountering an error with CRecordset::GetFieldValue(). It appears if I first get the value by name, and then try to get it by index, the return fails and returns CDBException. Example:
Code:
//res is a CRecordset * that is at the first row//
//get the field by name//
CString sSourceField = "SOMEFIELD";
CString sSourceValue;
res->GetFieldValue(sSourceField,sSourceValue);
//now loop through by index to get all the fields//
long nFields = res->GetODBCFieldCount();
for (long nIndex = 0; nIndex < nFields; nIndex++)
{
CString sValue;
res->GetFieldValue(nIndex,sValue);
//Fails to get "SOMEFIELD"'s value. Throws a CDBException
//but has no description of the error!//
}
I noticed if I try to get other fields by name before the loop as well, they also fail to be extracted later. Any ideas why I cannot get the same field value twice with two different approaches (by name and then by index)? Does the system lock itself once you use one approach?
-
March 24th, 2003, 10:16 PM
#2
Maybe because you forgot to move the cursor...
Code:
//res is a CRecordset * that is at the first row//
//get the field by name//
CString sSourceField = "SOMEFIELD";
CString sSourceValue;
res->GetFieldValue(sSourceField,sSourceValue);
// ...here...
res->MoveNext();
//now loop through by index to get all the fields//
long nFields = res->GetODBCFieldCount();
for (long nIndex = 0; nIndex < nFields; nIndex++)
{
CString sValue;
res->GetFieldValue(nIndex,sValue);
//Fails to get "SOMEFIELD"'s value. Throws a CDBException
//but has no description of the error!//
}
Regards,
Emanuel Vaduva
-
March 24th, 2003, 11:21 PM
#3
Just after getting the record, move the cursor to next record.
So that once you have fetched the current record, your cursor should point to next record. If this also doesn't work inform me, i will look again.
Tks
Anupam
-
March 25th, 2003, 01:26 PM
#4
What a riot! That did the trick!
I even called res->Move(0) and it fixed the problem. Talk about an undocumented bug!
Anyone want to trace it out and figure out why THAT happens? Why can you not GetFieldValue by fieldname first, then by index after?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|