Populating ADO fields dynamically in VC++ 
Author Message
 Populating ADO fields dynamically in VC++

Hi all,

I am having problems populating ADO fields dynamically in VC++.  Basically
I'm creating a new record and want to populate the fields without using the
class binding mechanism in VC++.

The following is a snip of the code :

  rec->Open(SelectAllSQL, db.GetInterfacePtr(), adOpenDynamic,
adLockOptimistic, adCmdText);

 FieldsPtr fields = rec->GetFields();
 if (fields == NULL)
  return;

 if (horzInfo->volName.size())
  {
   FieldPtr field = fields->GetItem("VOLUME");
   if (field)
      field->PutValue((_bstr_t)(horzInfo->volName.c_str()));
  }

Am I missing something obvious here?  Or is this not as simple as I think it
should be?

Mike



Sun, 18 May 2003 03:00:00 GMT
 Populating ADO fields dynamically in VC++

Here is how I did it.

Not even going to claim it is the right way or a good way. All I know is
that it works.

     //get the name of the field
     bstrName = _bstr_t
(PopSet->GetFields()->Item[(long)iFieldCounter]->Name);
     //get the value of the field (it must be a _bstr_t when it returns)
     bstrValue= ReturnBSTR(_variant_t
(PopSet->GetFields()->Item[(long)iFieldCounter]->Value));
     //turn the record data into an XML string (without field->Type...add
later)

the function ReturnBSTR is needed so you can turn it from a variant to a
BSTR. here is the function.

_bstr_t CGetXML::ReturnBSTR(_variant_t vInput)
{
 _bstr_t bstrReturn;
 switch(vInput.vt)
 {
  //long
  case VT_I4:
   bstrReturn = vInput.lVal;
  break;
  //double
  case VT_R8:
   bstrReturn = vInput.dblVal;
  break;
  //short
  case VT_I2:
   bstrReturn = vInput.lVal;
  break;
  //BSTR
  case VT_BSTR:
   bstrReturn = vInput.bstrVal;
  break;
  //float
  case VT_R4:
   bstrReturn = vInput.fltVal;
  break;
  //date
  case VT_DATE:
   bstrReturn = vInput.date;
  break;
  //NULL
  case VT_NULL:
   bstrReturn = "NULL";
  break;
  //BOOL
  case VT_BOOL:
   bstrReturn = vInput.boolVal;
  break;
  default:
   bstrReturn = "";
  break;
 }
 return bstrReturn;

Quote:
}

Hope that does it for you.

Lee Franke


Quote:
> Hi all,

> I am having problems populating ADO fields dynamically in VC++.  Basically
> I'm creating a new record and want to populate the fields without using
the
> class binding mechanism in VC++.

> The following is a snip of the code :

>   rec->Open(SelectAllSQL, db.GetInterfacePtr(), adOpenDynamic,
> adLockOptimistic, adCmdText);

>  FieldsPtr fields = rec->GetFields();
>  if (fields == NULL)
>   return;

>  if (horzInfo->volName.size())
>   {
>    FieldPtr field = fields->GetItem("VOLUME");
>    if (field)
>       field->PutValue((_bstr_t)(horzInfo->volName.c_str()));
>   }

> Am I missing something obvious here?  Or is this not as simple as I think
it
> should be?

> Mike



Mon, 19 May 2003 03:00:00 GMT
 Populating ADO fields dynamically in VC++
It did turn out to be something stupid...  I forgot to call rec->AddNew()
before populating the record.  Duh...

Mike

Quote:
> Hi all,

> I am having problems populating ADO fields dynamically in VC++.  Basically
> I'm creating a new record and want to populate the fields without using
the
> class binding mechanism in VC++.

> The following is a snip of the code :

>   rec->Open(SelectAllSQL, db.GetInterfacePtr(), adOpenDynamic,
> adLockOptimistic, adCmdText);

>  FieldsPtr fields = rec->GetFields();
>  if (fields == NULL)
>   return;

>  if (horzInfo->volName.size())
>   {
>    FieldPtr field = fields->GetItem("VOLUME");
>    if (field)
>       field->PutValue((_bstr_t)(horzInfo->volName.c_str()));
>   }

> Am I missing something obvious here?  Or is this not as simple as I think
it
> should be?

> Mike



Mon, 19 May 2003 03:00:00 GMT
 
 [ 3 post ] 

 Relevant Pages 

1. Error 3001 when creating adLongVarWChar or adLongVarBinary field dynamically in ADO recordset

2. Populating jtable dynamically

3. execute dynamically-built sql to populate local variable

4. Populating a ListView dynamically

5. How to populate Data Reports dynamically

6. yes/no field type in DataGrid(VC++ /ADO)

7. How to update the field with nullable in ADO of VC++6.0

8. ADO return Date Format for a recordset field value (VC++)

9. How to update field with nullable in ADO of VC++ 6.0

10. Newbie ADO VC++: How to get field by fieldnumber

11. Using ADO VC++ to add a new record to an Access table with one autonumber field

12. ADO return Date Format for a recordset field value (VC++)


 
Powered by phpBB® Forum Software