Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the method of realizing the ADO.NET recordset to get the number of records

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article to share with you is about the implementation of ADO. NET recordset to obtain the number of records is what, Xiaobian think quite practical, so share to everyone to learn, I hope you can read this article after harvest, not much to say, follow Xiaobian to see it.

VC use ADO technology to access the data table, open the data table, access to the ADO record set, how to obtain the number of records? A small problem, did not expect to have some meaning, practice completed, summed up.

Method 1: Open the data table in static, keyset cursor mode

p_hr = m_pRecordset->Open(_variant_t(bstrQuery),vNull,adOpenStatic,adLockOptimistic,adCmdText);

Then use the GetRecordCount() function to get the number of records.

m_pRecordset->GetRecordCount();

About ADO. NET Database Connection Pool Creation and Distribution

Analyzing ADO. NET using DataAdapter class

Simple and Practical ADO. NET Entity Framework Explained in Detail

Analysis of ADO. NET Entity Data Access and Change

Old Bird Summarizes ADO. NET Entity Framework Features

AdOpenKeyset can also be obtained using keyset cursors, but adOpenDynamic returns only-1. Multiple users use the same table, and the possibility of modifying it is very high, then *** use adOpenKeyset. If you are just browsing, use adOpenStatic to improve performance! Additions: adOpenStatic static cursor, other users 'modifications are invisible to the current user. adOpenDynamic cursor, all modifications to the current user are visible. The adOpenKeyset is a compromise between the first two and is available to the current user. But the performance is ***.

Method 2: Use SQL statements to implement

"select count(*) from Table name;", so you don't have to worry about the cursor's behavior.

Examples are as follows:

rs->Open("select COUNT(*) from tbUsersInfo",strCnn, adOpenKeyset,adLockOptimistic,adCmdText); long RecordCount; RecordCount=rs->Fields->GetItem((long)0)->GetValue();

Another example:

m_pRecordset = m_pConnection->Execute("SELECT COUNT(*) FROM table name ",&RecordsAffected,adCmdText); _variant_t vIndex = (long)0; _variant_t vCount = m_pRecordset->GetCollect(vIndex); CString message; message.Format(" %d records",vCount.lVal); AfxMessageBox(message);

Additional:

First, add the ADO recordset's

CursorLocation = adUseClient;

And then you can, in short, it feels very interesting, a small problem, but there are several different solutions, and for different databases, there are a little different.

The above is to achieve ADO. NET recordset to obtain the number of records is what, Xiaobian believes that some knowledge points may be our daily work will see or use. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report