🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.database.ado
6 messages
6 total messages Started by Bas Groeneveld Wed, 04 May 2005 07:34
Use of ADO Recordset
#803
Author: Bas Groeneveld
Date: Wed, 04 May 2005 07:34
27 lines
1710 bytes
Hi

I am having trouble using a pointer to an ADO Recordset15 object returned
from a COM control.

I can access the RecordCount variable with no problems, however I cannot
work out how to get to the actual field values.

Ideally I would like to assign the Recordset to a standard ADODataSet object
and take it from there. Is there a way to do this?

Otherwise what is the syntax to access the Recordset's field collection and
get to the field values. I was able to do this in C#.NET using:
    rs.Fields["FieldName"].Value.ToString();

I suspect that it is pretty straight forward. Is there a good reference to
this somewhere - the MSDN CD doesn't seem to help much.

Thanks
Bas
-- 

==========================================
Bas Groeneveld
Benchmark Design System and Software Engineering
PO Box 165N, Ballarat North, VIC 3350
Phone: +61 3 5333 5441  Mob: 0409 954 501
Re: Use of ADO Recordset
#804
Author: Viatcheslav V. Vassiliev
Date: Wed, 04 May 2005 10:04
46 lines
2565 bytes
Use recordset Fields collection, it has operator [] or GetItem() method. 
ADODataSet has property Recordset that you can use, it takes 
System::DelphiInterface< _Recordset >.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 + 
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Bas Groeneveld" <nospam@nospam.com.au> �������/�������� � �������� 
���������: news:42787b1f$1@newsgroups.borland.com...
> Hi
>
> I am having trouble using a pointer to an ADO Recordset15 object returned
> from a COM control.
>
> I can access the RecordCount variable with no problems, however I cannot
> work out how to get to the actual field values.
>
> Ideally I would like to assign the Recordset to a standard ADODataSet 
> object
> and take it from there. Is there a way to do this?
>
> Otherwise what is the syntax to access the Recordset's field collection 
> and
> get to the field values. I was able to do this in C#.NET using:
>    rs.Fields["FieldName"].Value.ToString();
>
> I suspect that it is pretty straight forward. Is there a good reference to
> this somewhere - the MSDN CD doesn't seem to help much.
>
> Thanks
> Bas
> -- 
>
> ==========================================
> Bas Groeneveld
> Benchmark Design System and Software Engineering
> PO Box 165N, Ballarat North, VIC 3350
> Phone: +61 3 5333 5441  Mob: 0409 954 501
>
>
> 
Re: Use of ADO Recordset
#805
Author: Bas Groeneveld
Date: Thu, 05 May 2005 00:11
44 lines
2224 bytes
"Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
news:42789e2f$1@newsgroups.borland.com...
> Use recordset Fields collection, it has operator [] or GetItem() method.

I did manage to get it going using the following

            wstUser =
adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;

However I was unable to get the [] operator working. Also the get_Item works
only on the field position, not the name. I expected to be able to go
something like

            wstUser = adoRS->Fields["User"]->Value().bstrVal;

Am I missing something here?

Also I could not access a GetItem method (as suggested in some ADO Recordset
documentation) but had to use get_Item instead.

> ADODataSet has property Recordset that you can use, it takes
> System::DelphiInterface< _Recordset >.

Thanks, I've got that to work.

Could you please tell me if the following code is correct. I especially
wondered if I need to dispose of the Recordset originally created with the
TADODataSet - or does that not exist until the Dataset is actually
populated?

    (Adodb_tlb::Recordset15*)ado = RxWClient->GetEmailAddresses(&ClientID);

    TADODataSet* ds = new TADODataSet(this);

    ds->Recordset = (Adoint::Recordset*)ado;

    ShowMessage(ds->FieldByName("Phone Number")->AsString);

    delete ds;

    ado->Close();

Cheers
Bas
Re: Use of ADO Recordset
#806
Author: Viatcheslav V. Vassiliev
Date: Thu, 05 May 2005 06:08
75 lines
3485 bytes
In type library Item is property, and GetItem, get_Item and/or [] depends on 
program that imports type library. [] are imported, if I am not wrong, by 
C++ Builder 6, but not earlier.

>            wstUser =
> adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;

try

adoRS->Fields->getItem(WideString("User"))->get_Value();

Recordset is disposed when you assign new recordset, you do not need to 
dispose it. You need to release your pointer to recordset (ado) - you may do 
it just after assigning recordset to TADODataSet, Close() will be called by 
TADODataSet.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 + 
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Bas Groeneveld" <nospam@nospam.com.au> �������/�������� � �������� 
���������: news:42796494@newsgroups.borland.com...
> "Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
> news:42789e2f$1@newsgroups.borland.com...
>> Use recordset Fields collection, it has operator [] or GetItem() method.
>
> I did manage to get it going using the following
>
>            wstUser =
> adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;
>
> However I was unable to get the [] operator working. Also the get_Item 
> works
> only on the field position, not the name. I expected to be able to go
> something like
>
>            wstUser = adoRS->Fields["User"]->Value().bstrVal;
>
> Am I missing something here?
>
> Also I could not access a GetItem method (as suggested in some ADO 
> Recordset
> documentation) but had to use get_Item instead.
>
>> ADODataSet has property Recordset that you can use, it takes
>> System::DelphiInterface< _Recordset >.
>
> Thanks, I've got that to work.
>
> Could you please tell me if the following code is correct. I especially
> wondered if I need to dispose of the Recordset originally created with the
> TADODataSet - or does that not exist until the Dataset is actually
> populated?
>
>    (Adodb_tlb::Recordset15*)ado = RxWClient->GetEmailAddresses(&ClientID);
>
>    TADODataSet* ds = new TADODataSet(this);
>
>    ds->Recordset = (Adoint::Recordset*)ado;
>
>    ShowMessage(ds->FieldByName("Phone Number")->AsString);
>
>    delete ds;
>
>    ado->Close();
>
> Cheers
> Bas
>
> 
Re: Use of ADO Recordset
#807
Author: Bas Groeneveld
Date: Fri, 06 May 2005 06:48
28 lines
1924 bytes
> In type library Item is property, and GetItem, get_Item and/or [] depends
on
> program that imports type library. [] are imported, if I am not wrong, by
> C++ Builder 6, but not earlier.

Interesting I am using C++Builder 6 but definitely don't appear to have []
available.

>
> >            wstUser =
> > adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;
>
> try
>
> adoRS->Fields->getItem(WideString("User"))->get_Value();

wstUser = adoRS->Fields->get_Item(WideString("User"))->get_Value().bstrVal;
- generates a compiler error [C++ Error] fRxWorks.cpp(134): E2285 Could not
find a match for 'Fields15::get_Item(WideString)'

wstUser = adoRS->Fields->get_Item(Variant("User"))->get_Value().bstrVal;
- compiles but generates a runtime error reported by OLECHECK

wstUser = adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;
- compiles and runs ok

Cheers
Bas
Re: Use of ADO Recordset
#809
Author: Viatcheslav V. Vassiliev
Date: Sun, 08 May 2005 17:00
63 lines
2999 bytes
OleVariant v =
ADODataSet1->Recordset->Fields->Item[WideString("au_id")]->Value;


Remove OLECHECK (compile-time) in C++ Builder 6 (not needed in earlier):

#include <comobj.hpp>

namespace System
{
 void __fastcall CheckSafecallResult(HRESULT hr)
 {
  OleCheck(hr);
 }
}

When converting OleVariant, use (WideString)v or similar, you may have
OleVariant with other type that VT_BSTR and use .bstr() may have
unpredictable results - for example, you may get OleVariant with type
VT_NULL.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Bas Groeneveld" <nospam@nospam.com.au> �������/�������� � �������� 
���������: news:427b1331@newsgroups.borland.com...
>> In type library Item is property, and GetItem, get_Item and/or [] depends
> on
>> program that imports type library. [] are imported, if I am not wrong, by
>> C++ Builder 6, but not earlier.
>
> Interesting I am using C++Builder 6 but definitely don't appear to have []
> available.
>
>>
>> >            wstUser =
>> > adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;
>>
>> try
>>
>> adoRS->Fields->getItem(WideString("User"))->get_Value();
>
> wstUser = 
> adoRS->Fields->get_Item(WideString("User"))->get_Value().bstrVal;
> - generates a compiler error [C++ Error] fRxWorks.cpp(134): E2285 Could 
> not
> find a match for 'Fields15::get_Item(WideString)'
>
> wstUser = adoRS->Fields->get_Item(Variant("User"))->get_Value().bstrVal;
> - compiles but generates a runtime error reported by OLECHECK
>
> wstUser = adoRS->Fields->get_Item(Variant(1))->get_Value().bstrVal;
> - compiles and runs ok
>
> Cheers
> Bas
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads