Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CRecordset::MoveFirst()

Status
Not open for further replies.

mpsoutine

Programmer
Jan 6, 2003
87
US
Hi,

I'm trying to get a better understanding of this function.

In MSDN: MoveFirst() call this member function to make the first record in the first rowset the current record.

I'm getting stuck on the term rowset. What is meant by the term "first rowset"

Thanks,
 
When you write a query, results are grouped into rowsets: groups of records matching your query. An individual rowset is a group that your application can directly access from memory - the rest of matching records are in "virtual memory" (disk or other caches).

Dimandja
 
Hi Dimandja,

Thanks for the feedback. Where I'm a little confused is with the term "first rowset" Would this be the first record? Below is the code I'm working with. I'm using the contents of a CRecordset to populate a list control. I'm using the code as a guide. I did not write it.
I'm trying to understand what MoveFirst,MoveLast and MoveNext are doing in while() loop. I works but I want to understand it.

I keep thinking that I'm moving records around in the record set. IS THIS TRUE?

Or am I just moving through the records and making the record I've moved to the CURRENT RECORD?


void CPersonSet::AddItem(CListCtrl *pList)
{


AfxMessageBox("AddItem() called");

CPersonSet TmpSet;

int lcPos = 0;
int NextItem;

CString x;

TmpSet.m_strSort = "PersonID DESC";
if(!TmpSet.IsOpen())
{

AfxMessageBox("Not Open");
TmpSet.Open();

}


//The SetItemData() will set be set to the PersonID. That way if two
//people have the same names they will have different ID's


while(!TmpSet.IsEOF())
{

TmpSet.MoveFirst();

//Now that I have the value of the PersonID in the last record
//I want to add this to the list control

NextItem = pList->InsertItem(0,TmpSet.m_PersonLast);
pList->SetItemText(NextItem,1,TmpSet.m_PersonFirst);

pList->SetItemData(NextItem,TmpSet.m_PersonID);


TmpSet.MoveLast();
TmpSet.MoveNext();
}

 
Hi mpsoutine,

Recordset represents the entire set of records from a base table or the results of an executed command. At any time, the Recordset object refers to only a single record within the set as the current record.

Movefirst, MoveLast, MoveNext are simply moving the pointer or cursor position the the first or last or next row, making it the current record.

The rowset size specifies how many records (rowset) should be retrieved during a single fetch.

Class CRecordset provides support for bulk row fetching, which means that multiple records can be retrieved at once during a single fetch, rather than retrieving one record at a time from the data source.

You can find more help about this at
Dimandja
 
Hi Dimandja,

I've been reading the msdn site you mentioned. What I'm still confused on is what is taking place with in the while()loop.

When the recordset is opened I call MoveFirst() and then populate the List Control with the contents of the record.

Next I call MoveLast().This will bring me to the last record set.

Next I call MoveNext().This is where I'm confused. If I'm at the last record in the record set how am I able to move to the second record?
 
I must admit that I haven't given much thought to that code - since its intention is unclear (test only?, production?, what needs to be done?).

However consider this statement: while(!TmpSet.IsEOF()). The loop will continue until EOF on TmpSet. MoveLast will point to the last row in that set - wich could also be the first record when there is only one record; but then, MoveNext will cause an EOF, ending the loop.

Dimandja
 
Hi Dimandja,

This code is being used to add an item that was recently added to the recordset to a list control. But I figured out why MoveLast and MoveNext are called. I'm only adding ONE record to the list control NOT repopulating the the list control with the entire contents of a recordset. I already have a function that populates the list control. Since I'm only adding one record I need to get out of the while()loop after reading the recently added record. Hence the reason for the order of MoveLast and MoveNext. I see where I was making the mistake. I was thinking the code was repopulating the list control instead of only adding one record. Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top