 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bas Groeneveld Guest
|
Posted: Wed May 04, 2005 7:34 am Post subject: Use of ADO Recordset |
|
|
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
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Wed May 04, 2005 10:04 am Post subject: Re: Use of ADO Recordset |
|
|
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 (AT) nospam (DOT) com.au> сообщил/сообщила в новостях
следующее: news:42787b1f$1 (AT) newsgroups (DOT) borland.com...
| Quote: | 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
|
|
|
| Back to top |
|
 |
Bas Groeneveld Guest
|
Posted: Thu May 05, 2005 12:11 am Post subject: Re: Use of ADO Recordset |
|
|
"Viatcheslav V. Vassiliev" <support (AT) oledbdirect (DOT) com> wrote
| Quote: | 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.
| Quote: | 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
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Thu May 05, 2005 6:08 am Post subject: Re: Use of ADO Recordset |
|
|
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.
| Quote: | 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 (AT) nospam (DOT) com.au> сообщил/сообщила в новостях
следующее: news:42796494 (AT) newsgroups (DOT) borland.com...
| Quote: | "Viatcheslav V. Vassiliev" <support (AT) oledbdirect (DOT) com> wrote in message
news:42789e2f$1 (AT) newsgroups (DOT) 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
|
|
|
| Back to top |
|
 |
Bas Groeneveld Guest
|
Posted: Fri May 06, 2005 6:48 am Post subject: Re: Use of ADO Recordset |
|
|
| Quote: | 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.
| Quote: |
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
|
|
| Back to top |
|
 |
Viatcheslav V. Vassiliev Guest
|
Posted: Sun May 08, 2005 5:00 pm Post subject: Re: Use of ADO Recordset |
|
|
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 (AT) nospam (DOT) com.au> сообщил/сообщила в новостях
следующее: news:427b1331 (AT) newsgroups (DOT) borland.com...
| Quote: | 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
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|