Re: RecordsetPtr & Command's Execute() method

From: Chris Martin (nospam_at_please11111.net)
Date: 02/27/04


Date: Fri, 27 Feb 2004 05:33:05 GMT

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

  • Re: recordset not opening even though query analyzer returns resul
    ... I'm convinced that VB can execute this complex SP. ... > only way i could get an earlier version of it to return in a recordset. ... > table into a cursor and add up th evalues of the ccjs based on values in ... >> execute a query the SQL engine returns a resultset. ...
    (microsoft.public.vb.database.ado)
  • Re: UPDATE query in Access 2003 raising error
    ... The only reason I questioned the recordset is that you could conceivably ... the SQL looks fine to me. ... Set qdfTemp = db.CreateQueryDef ... Elsewhere in the code I use the same technique to execute an SQL statement ...
    (microsoft.public.access.formscoding)
  • Re: DAO peculiarity in A97?
    ... If BOF is True then you won't execute the statements inside the ... If..Then becuase you have told it to continue only if the opposite of BOF is ... only thing you do with it is open a recordset. ... This will force you to DIM each variable you ...
    (comp.databases.ms-access)
  • RE: Still struggling
    ... DLookup is much faster to execute and easier to code than creating, opening, ... using SQL is always faster than recordset processing. ... But, you do have to use the dbFailOnError option because without it, Access ...
    (microsoft.public.access.forms)
  • Re: GetRows Method
    ... Therefore the time to execute the Open is constant in both scenarios. ... It moves the data from the recordset to the aVarray, ... The article stated "The GetRows method is used to pull all the records from the recordset into an array." ... The usual purpose of opening a recordset is to process data. ...
    (microsoft.public.vb.database.ado)