Re: RecordsetPtr & Command's Execute() method

From: Val Mazur (group51a_at_hotmail.com)
Date: 02/28/04


Date: Sat, 28 Feb 2004 13:28:38 -0500

Hi Chris,

It is exact same as a another type of the recordset, but just has some
limitations. I am not a C++ guy, but I will try to describe some limitations
and usage.
First if all, when you open read-only, forward-only recordset, you need to
check EOF property to see if recordset has anything. In VB it looks like

Set MyRecordset=MyCommand.Execute "SELECT ...."
If Not .EOF Then
    'Do some staff here
end if

Since you cannot get record count, you need to use EOF property of the
recordset to check if you have any records. Now you can navigate recordset,
but here you have some limitations. First you can use only MoveFirst,
MoveNext, MoveLast methods, not MovePrevious. In case of MoveNext and
MoveLast, provider just scrolls recordset to the next or to the last record.
In case of MoveFirst, provider re-opens recordset again. It happens because
virtually you cannot move back and provider has to open cursor again. This
is basically main difference between forward-only and other types of the
recordset. If you have any specific questions, then you could post them here

-- 
Val Mazur
Microsoft MVP
"Chris Martin" <nospam@please11111.net> wrote in message 
news:lEA%b.130741$jk2.545383@attbi_s53...
> Thanks for the reply.  I guess my real problem is I don't know how to use
> this a read-only, forward-only Recordset.  If anyone could provide some
> sample code or an MSDN article, that'd be great.
>
> Thanks,
> C. Martin
>
> "Val Mazur" <group51a@hotmail.com> wrote in message
> news:OTPXBVO$DHA.2516@TK2MSFTNGP11.phx.gbl...
>> Hi Chris,
>>
>> Do you want to say that you do not like recordcount -1? If yes, then it 
>> is
>> expected result in your case, because recordset is read-only, 
>> forward-only
>> and provider is not capable to return actual record count in this case,
> but
>> recordset is opened and you could use it. Check next KB for more
> information
>>
>> http://support.microsoft.com/default.aspx?scid=kb;en-us;194973
>>
>> -- 
>> Val Mazur
>> Microsoft MVP
>>
>> "Chris Martin" <nospam@please11111.net> wrote in message
>> news:o_x%b.130127$jk2.542397@attbi_s53...
>> >I am trying to get back data from a "SELECT" query, and am having 
>> >trouble
>> > doing anything with the RecordsetPtr returned from a Command's 
>> > Execute()
>> > method.  The docs say:
>> >
>> >> The returned Recordset object is always a read-only, forward-only
> cursor.
>> >
>> > Am I doing something incorrect in accessing the data from this
> Recordset?
>> > I
>> > have gotten SELECT queries to work using Recordset's Open() method, but
> I
>> > wanted to use the Command's Execute() instead.
>> >
>> > If there is a good reason for using a different method, please explain.
>> >
>> > /* code simplified for brevity */
>> > _ConnectionPtr m_pConnection;
>> > _CommandPtr m_pCommand;
>> > _RecordsetPtr pRs;
>> >
>> > m_pConnection.CreateInstance(__uuidof(Connection));
>> > m_pCommand.CreateInstance(__uuidof(Command));
>> >
>> > m_pConnection->Open(m_strConn, lpstrUserID, lpstrPword, NULL);
>> >
>> > m_pCommand->ActiveConnection = m_pConnection;
>> > m_pCommand->CommandText = "SELECT * FROM Customers";
>> >
>> > pRs = m_pCommand->Execute(NULL, NULL, adCmdText);
>> >
>> > long count = pRs->GetRecordCount(); // returns -1
>> > _bstr_t str = pRs->GetString(adClipString, 1, ",", "\n", ""); // 
>> > returns
>> > garbage
>> > /* end */
>> >
>> > TIA,
>> > C. Martin
>> >
>> >
>>
>>
>
> 


Relevant Pages

  • How do I work with Recordset in ExecuteComplete event?
    ... I want to use Recordset external to the ExecuteComplete event. ... I created my own recordset and assigned in the event as MyRecortdset:= Recordset. ... Probably my limitations are getting in the way here, so if anyone knows of some good reference material on this subject, please let me know. ...
    (borland.public.delphi.database.ado)
  • Re: Error -2147418113 with AddNew in transaction
    ... > Microsoft OLE DB Provider for SQL Server 7.01 ... > Any operation following a rollback or a commit transaction on a recordset ... > The OLE DB provider must support preserving cursors. ... > SQL Server supports preserving cursors on Commit and Abort. ...
    (microsoft.public.data.ado)
  • Re: Data provider or other service returned an E_FAIL status every
    ... 'repeat each merge above for each recordset ... SQLOLEDB provider and that the stream itself is using a TEXT provider. ... For Each objField In recSourceClone.Fields ... I am thinking I could run a connection ...
    (microsoft.public.data.ado)
  • Re: Newbie Q. for referencing DAO recordsets with VBA in Access front
    ... recordset. ... designer, keep in mind that sometimes the columns are renamed to something ... isn´t supported by that provider. ... HTH, Jens Suessmeyer. ...
    (microsoft.public.sqlserver.msde)
  • Re: MDAC 2.8 vs MDAC 2.7
    ... Actually RecordCount has to do with the provider, ... If just changing of the connection string to use OLEDB provider solves this ... then it looks like a bug in OLEDB for ODBC provider or in ODBC ... But do you get an actual recordset opened in your case? ...
    (microsoft.public.data.ado)