小弟编程遇到一个莫名其妙的问题:执行一个Select语句,想得到所取得的记录的个数。该语句在数据库工具(TOAD)中执行的结果是取得了一条记录,但recordset对象返回的RecordCount的值为0,那位大虾能帮我分析分析?下面是小弟实现的代码 Dim strSQL As String
Dim rs As ADODB.Recordset strSQL ="select field1 from table1 where condition=1"
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Source = sTmp
rs.ActiveConnection = ""Provider=OraOLEDB.Oracle.1;Password=xxx;Persist Security Info=True;User ID=xxx;Data Source=xxx"
"
rs.Open 得到的rs.RecordCount等于0,请各位高手指点,感激不尽。
Dim rs As ADODB.Recordset strSQL ="select field1 from table1 where condition=1"
Set rs = CreateObject("ADODB.Recordset")
rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Source = sTmp
rs.ActiveConnection = ""Provider=OraOLEDB.Oracle.1;Password=xxx;Persist Security Info=True;User ID=xxx;Data Source=xxx"
"
rs.Open 得到的rs.RecordCount等于0,请各位高手指点,感激不尽。
strSQL="select count(field1) counter from table1 where condition=1"
此时,rs.RecordCount的值为1,但rs.fields("counter")的值为0,晕倒!
对了,我在rs.open后面还漏了一句
Set rs.ActiveConnection = Nothing
如果你指的是这个,好像也没有效果:(
rs.CursorType = adOpenKeyset(键集RecordSet)
或
rs.CursorType =adOpenStatic (静态RecordSet)
msgbox rs.reordcordcount
这时候,rs.movelast好像是不能运行的吧:)
Dim rs As New ADODB.Recordset
Dim strSQL As String
conn.ConnectionString = "Provider=OraOLEDB.Oracle.1;Password=xxx;Persist Security Info=True;User ID=xxx;Data Source=xxx"
conn.CommandTimeout = 30
conn.Open
strSQL = "select field1 from table1 where condition=1"
rs.Open strSQL, conn, adOpenKeyset, adLockOptimistic
Debug.Print rs.RecordCount
strSQL.Format("select COUNT(*) from %s",Table);
pCommand->CommandText=(_bstr_t)strSQL;
pCommand->CommandType=adCmdText;
pCommand->Parameters->Refresh();
MySet=pCommand->Execute(NULL,NULL,adCmdUnknown);
_variant_t vIndex = (long)0;
_variant_t vCount = MySet->GetCollect(vIndex);///取得第一个字段的值放入vCount变量
m_ItemCount=vCount.lVal;
rs.open strSQL, conn, adOpenKeyset, adLockOptimistic
试试
不过我想md2d()的意见是正确的。其他人的想法也都不错,再次谢谢大家。