选择计数(*)问题 [英] Select Count(*) problem
问题描述
vb6,ado,mdb,win2k
i将sql字符串传递给打开连接上的.Execute方法
Table_Name(const)db table
fwiw
(通过类包装器打开的连接:)
msConnString =" Data Source =" &安培; msDbFilename
moConn.Properties(" Persist Security Info")= False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite''或使用默认...相同结果
moConn.Open
似乎无法让我的sql正确
这里是我试过的很多方法的几个版本产生的错误
代码每个后面
''sSql ="选择计数(*)为''总计''来自' &安培; TABLE_NAME& _
''" WHERE fldType.Value =''" &安培; sType& "'''AND" &安培; _
''" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
sSql ="选择计数(*)为''总计''来自' &安培; TABLE_NAME& _
" WHERE fldTypeName.Value =''" &安培; sType& "'''AND" &安培; _
" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
" fldCondLBR.Value ='''2L''ORDER BY fldTypeName"
''ErrState:-2147217887<您试图执行不包含
指定表达式的查询''fldTypeName''作为聚合函数的一部分。>
''sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''" WHERE fldTypeName.Value =''" &安培; sType& "'''AND" &安培; _
''" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
' 'sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value ='''2L''"
''ErrState:-2147217900(无效使用''。'',''! '','或''()''。在查询中
表达式''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName'')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value =''3 ''AND
tblTypeCond.Fields.Item(''fldCondLBR'')。Value =''2L''''。)
''s sql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value ='''2L''"
''ErrState:-2147217900(无效使用''。'',''! '','或''()''。在查询中
表达式''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName'')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value =''4 ''AND
tblTypeCond.Fields.Item(''fldCondLBR'')。Value =''2L''''。)
''s sql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .fldTypeName.Value =''" &安培; sType& "''
AND" &安培; _
''TABLE_NAME& .fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''TABLE_NAME& .fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''TABLE_NAME& " .fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
'' sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value =''''2L''''"
''ErrState:-2147217900(查询中的语法错误(缺少运算符)表达
''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName' ')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value ='''4''和
tblTypeCond。 Fields.Item(''fldCondLBR'')。Value =''''2L'''''。
消除where子句可能是'问题所在?
''尝试执行sql<选择计数(*)为''总计''来自tblTypeCond>
''ErrState:ErrNum 3265(物品无法找到收集相应的
到所要求的名称或序数。)
yikes ...问题是什么???
>
我的想法用完了
任何帮助?
谢谢
Mark
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source=" & msDbFilename
moConn.Properties("Persist Security Info") = False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite'' or using default...same result
moConn.Open
can''t seem to get my sql right
here''s a few versions of the many ways i''ve tried with the resulting error
codes following each
'' sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
'' " WHERE fldType.Value = ''" & sType & "'' AND " & _
'' " fldCondName.Value = ''" & sCond & "'' AND " & _
'' " fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
" WHERE fldTypeName.Value = ''" & sType & "'' AND " & _
" fldCondName.Value = ''" & sCond & "'' AND " & _
" fldCondVar.Value = ''" & sCondVar & "'' AND " & _
" fldCondLBR.Value = ''2L'' ORDER BY fldTypeName"
''ErrState: -2147217887 <You tried to execute a query that does not include
the specified expression ''fldTypeName'' as part of an aggregate function.>
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE fldTypeName.Value = ''" & sType & "'' AND " & _
'' " fldCondName.Value = ''" & sCond & "'' AND " & _
'' " fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''2L''"
''ErrState: -2147217900 (Invalid use of ''.'', ''!'', or ''()''. in query
expression ''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''3'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''2L''''.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''2L''"
''ErrState: -2147217900 (Invalid use of ''.'', ''!'', or ''()''. in query
expression ''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''4'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''2L''''.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".fldTypeName.Value = ''" & sType & "''
AND " & _
'' TABLE_NAME & ".fldCondName.Value = ''" & sCond & "'' AND " & _
'' TABLE_NAME & ".fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' TABLE_NAME & ".fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''''2L''''"
''ErrState: -2147217900 (Syntax error (missing operator) in query expression
''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''4'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''''2L''''''.)
eliminate the where clause maybe that''s the problem?
''Try execute sql <Select Count(*) As ''Total'' From tblTypeCond>
''ErrState: ErrNum 3265 (Item cannot be found in the collection corresponding
to the requested name or ordinal.)
yikes...what''s the problem???
i''m running out of ideas
any help?
Thanks
Mark
推荐答案
MP写道:
MP wrote:
vb6,ado,mdb,win2k
i将sql字符串传递给打开连接上的.Execute方法
Table_Name(const)db table
fwiw
(通过类包装器打开的连接:)
msConnString =" Data Source =" &安培; msDbFilename
moConn.Properties(" Persist Security Info")= False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite''或使用默认值...相同结果
moConn.Open
似乎无法得到我的sql
这里是我尝试过的很多方法的几个版本产生的错误
代码跟随每个
''sSql ="选择计数(*)为''总计''来自' &安培; TABLE_NAME& _
''" WHERE fldType.Value =''" &安培; sType& "'''AND" &安培; _
''" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
sSql ="选择计数(*)为''总计''来自' &安培; TABLE_NAME& _
" WHERE fldTypeName.Value =''" &安培; sType& "'''AND" &安培; _
" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
" fldCondLBR.Value ='''2L''ORDER BY fldTypeName"
''ErrState:-2147217887<您试图执行不包含
指定表达式的查询''fldTypeName''作为聚合函数的一部分。>
''sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''" WHERE fldTypeName.Value =''" &安培; sType& "'''AND" &安培; _
''" fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
' 'sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value ='''2L''"
''ErrState:-2147217900(无效使用''。'',''! '','或''()''。在查询中
表达式''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName'')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value =''3 ''AND
tblTypeCond.Fields.Item(''fldCondLBR'')。Value =''2L''''。)
''s sql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value ='''2L''"
''ErrState:-2147217900(无效使用''。'',''! '','或''()''。在查询中
表达式''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName'')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value =''4 ''AND
tblTypeCond.Fields.Item(''fldCondLBR'')。Value =''2L''''。)
''s sql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .fldTypeName.Value =''" &安培; sType& "''
AND" &安培; _
''TABLE_NAME& .fldCondName.Value =''" &安培; sCond& "'''AND" &安培; _
''TABLE_NAME& .fldCondVar.Value =''" &安培; sCondVar& "'''AND" &安培; _
''TABLE_NAME& " .fldCondLBR.Value ='''2L''"
''ErrState:-2147217904(没有给出一个或多个必需参数的值。)
''sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''"在哪里 &安培; TABLE_NAME& " .Fields.Item(''fldTypeName'')。Value =''"
& sType& "'''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondName'')。Value =''" &安培; sCond& "''
AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondVar'')。Value =''" &安培; sCondVar&
"''AND" &安培; _
''TABLE_NAME& " .Fields.Item(''fldCondLBR'')。Value =''''2L''''"
''ErrState:-2147217900(查询中的语法错误(缺少运算符)表达
''tblTypeCond.Fields.Item(''fldTypeName'')。Value =''A''AND
tblTypeCond.Fields.Item(''fldCondName' ')。Value =''1''和
tblTypeCond.Fields.Item(''fldCondVar'')。Value ='''4''和
tblTypeCond。 Fields.Item(''fldCondLBR'')。Value =''''2L'''''。
消除where子句可能是'问题所在?
''尝试执行sql<选择计数(*)为''总计''来自tblTypeCond>
''ErrState:ErrNum 3265(物品无法找到收集相应的
到所要求的名称或序数。)
yikes ...问题是什么???
>
我的想法用完了
任何帮助?
谢谢
M ark
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source=" & msDbFilename
moConn.Properties("Persist Security Info") = False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite'' or using default...same result
moConn.Open
can''t seem to get my sql right
here''s a few versions of the many ways i''ve tried with the resulting error
codes following each
'' sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
'' " WHERE fldType.Value = ''" & sType & "'' AND " & _
'' " fldCondName.Value = ''" & sCond & "'' AND " & _
'' " fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
" WHERE fldTypeName.Value = ''" & sType & "'' AND " & _
" fldCondName.Value = ''" & sCond & "'' AND " & _
" fldCondVar.Value = ''" & sCondVar & "'' AND " & _
" fldCondLBR.Value = ''2L'' ORDER BY fldTypeName"
''ErrState: -2147217887 <You tried to execute a query that does not include
the specified expression ''fldTypeName'' as part of an aggregate function.>
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE fldTypeName.Value = ''" & sType & "'' AND " & _
'' " fldCondName.Value = ''" & sCond & "'' AND " & _
'' " fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''2L''"
''ErrState: -2147217900 (Invalid use of ''.'', ''!'', or ''()''. in query
expression ''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''3'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''2L''''.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''2L''"
''ErrState: -2147217900 (Invalid use of ''.'', ''!'', or ''()''. in query
expression ''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''4'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''2L''''.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".fldTypeName.Value = ''" & sType & "''
AND " & _
'' TABLE_NAME & ".fldCondName.Value = ''" & sCond & "'' AND " & _
'' TABLE_NAME & ".fldCondVar.Value = ''" & sCondVar & "'' AND " & _
'' TABLE_NAME & ".fldCondLBR.Value = ''2L''"
''ErrState: -2147217904 (No value given for one or more required parameters.)
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE " & TABLE_NAME & ".Fields.Item(''fldTypeName'').Value = ''"
& sType & "'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondName'').Value = ''" & sCond & "''
AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondVar'').Value = ''" & sCondVar &
"'' AND " & _
'' TABLE_NAME & ".Fields.Item(''fldCondLBR'').Value = ''''2L''''"
''ErrState: -2147217900 (Syntax error (missing operator) in query expression
''tblTypeCond.Fields.Item(''fldTypeName'').Value = ''A'' AND
tblTypeCond.Fields.Item(''fldCondName'').Value = ''1'' AND
tblTypeCond.Fields.Item(''fldCondVar'').Value = ''4'' AND
tblTypeCond.Fields.Item(''fldCondLBR'').Value = ''''2L''''''.)
eliminate the where clause maybe that''s the problem?
''Try execute sql <Select Count(*) As ''Total'' From tblTypeCond>
''ErrState: ErrNum 3265 (Item cannot be found in the collection corresponding
to the requested name or ordinal.)
yikes...what''s the problem???
i''m running out of ideas
any help?
Thanks
Mark
您无需取消引用列名称来确定或设置
值。举个例子:
sSql ="选择Count(*)As''Total''From" &安培; TABLE_NAME& _
You don''t need to dereference the column names to determine or set the
value. Taking your first example:
sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
''" WHERE fldType =''" &安培; sType& "'''AND" &安培; _
''" fldCondName =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR ='''2L''"
'' " WHERE fldType = ''" & sType & "'' AND " & _
'' " fldCondName = ''" & sCond & "'' AND " & _
'' " fldCondVar = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR = ''2L''"
等。显然我不能保证这个的实际功效,因为
你不提供表格定义。
爱德华
etc. Obviously I can''t vouch for the actual efficacy of this, since
you don''t provide table defs.
Edward
< te ******* *@hotmail.com写信息
新闻:11 ********************** @ b28g2000cwb.googlegr oups.com ...
<te********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
您无需取消引用列名称来确定或设置
值。举个例子:
sSql ="选择Count(*)As''Total''From" &安培; TABLE_NAME& _
>
You don''t need to dereference the column names to determine or set the
value. Taking your first example:
sSql = "Select Count(*) As ''Total'' From " & TABLE_NAME & _
''" WHERE fldType =''" &安培; sType& "'''AND" &安培; _
''" fldCondName =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR ='''2L''"
'' " WHERE fldType = ''" & sType & "'' AND " & _
'' " fldCondName = ''" & sCond & "'' AND " & _
'' " fldCondVar = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR = ''2L''"
等。显然我不能保证这个的实际效果,因为
你没有提供表格定义。
爱德华
etc. Obviously I can''t vouch for the actual efficacy of this, since
you don''t provide table defs.
Edward
感谢您的关注。
我知道我没有*需要*明确使用.Value但我总是听说它最好不要依赖默认属性。
我不确定它''*错误*在Select
语句中明确指定.Value ......但也许是。
无论如何它仍然无法正常工作,错误运行以上是:
''ErrState:ErrNum 3265(物品在集合中找不到相应的
到所请求的名称或序号。)
第一个例子中有一个拼写错误但我在再次运行这个
之前修复了它... fldType是fldTypeName
实际的字符串运行是:
'sSql =" Select Count(*)From" &安培; TABLE_NAME& _
''" WHERE fldTypeName =''" &安培; sType& "'''AND" &安培; _
''" fldCondName =''" &安培; sCond& "'''AND" &安培; _
''" fldCondVar =''" &安培; sCondVar& "'''AND" &安培; _
''" fldCondLBR ='''2L''"
在编程的早期我运行一个字符串来获得一个独特的组
sSql =" SELECT DISTINCT fldTypeName, fldCondName,fldCondvar,fldcondlbr"
& _
"来自 &安培; TABLE_NAME& _
" ORDER BY fldTypeName,fldCondName,fldCondvar,fldcondlbr"
FormReport"尝试执行sql<" &安培; sSql& ">"
设置oRs = moDb.Execute(sSql)
返回一个包含多条记录的集合,因此字段名称正确
(Table_Name是表名的字符串常量。)
现在我正在尝试使用相同的开放连接来获取另一个记录集
计数
也许你不能重复使用连接?????
我循环上面的记录集试图获取每个组的计数
其中
虽然不是oRs.EOF
sType = oRs.Fields.Item(" fldTypeName")。价值
sCond = oRs.Fields.Item(" fldCondName")。值
sCondVar = oRs.Fields.Item(" fldCondVar")。值
FormReport" Check" &安培; sType& sCond& sCondVar
所以现在我用这些变量构建sql字符串
sSql =" Select Count(*)From" &安培; TABLE_NAME& _
" WHERE fldTypeName =''" &安培; sType& "'''AND" &安培; _
" fldCondName =''" &安培; sCond& "'''AND" &安培; _
" fldCondVar =''" &安培; sCondVar& "'''AND" &安培; _
" fldCondLBR ='''2L''"
''尝试通过相同的连接获得另一个记录集... mayb问题是什么?
设置oRsCount = moDb.Execute(sSql)
当我收到错误时那就好了
我甚至不能放弃所有的东西'并让它工作
sSql =" Select Count(*)From" &安培; TABLE_NAME
尝试执行sql<从tblTypeCond选择计数(*)>
ErrState:ErrNum 3265(项目在相应的集合中找不到
到所请求的名字或序号。)
我知道我没有一个名为Count的字段或一个名为*的字段但我认为
是一个应该可以在任何桌子上运行的通用功能...
你看到我做错了吗?
我花的钱4个小时谷歌阅读大量的帖子选择计数(*)等
并没有看到我做错了。
谢谢
mark
Thanks for looking at it.
I knew I didn''t *need* to explicitly use .Value but I always heard it''s best
not to rely on default properties.
I''m not sure its'' *wrong* to explicitly specify the .Value in a Select
statement either...but maybe it is.
In any case it still doesn''t work, the error running the above is:
''ErrState: ErrNum 3265 (Item cannot be found in the collection corresponding
to the requested name or ordinal.)
There was a typo in the first example but i fixed it before running this
again ... fldType is fldTypeName
the actual string run was:
'' sSql = "Select Count(*) From " & TABLE_NAME & _
'' " WHERE fldTypeName = ''" & sType & "'' AND " & _
'' " fldCondName = ''" & sCond & "'' AND " & _
'' " fldCondVar = ''" & sCondVar & "'' AND " & _
'' " fldCondLBR = ''2L''"
Earlier in the prog I run a string to get a distinct group
sSql = "SELECT DISTINCT fldTypeName, fldCondName, fldCondvar, fldcondlbr"
& _
" FROM " & TABLE_NAME & _
" ORDER BY fldTypeName, fldCondName, fldCondvar, fldcondlbr"
FormReport "Try execute sql <" & sSql & ">"
Set oRs = moDb.Execute(sSql)
that returns me a set with several records so the field names are right
(Table_Name is a string constant for the table name.)
now i''m trying to use the same open connection to get another recordset with
the count
maybe you cant'' reuse a connection?????
i''m looping through the above recordset to try to get a count for each group
within it
While Not oRs.EOF
sType = oRs.Fields.Item("fldTypeName").Value
sCond = oRs.Fields.Item("fldCondName").Value
sCondVar = oRs.Fields.Item("fldCondVar").Value
FormReport "Check " & sType & sCond & sCondVar
so now i build the sql string using those variables
sSql = "Select Count(*) From " & TABLE_NAME & _
" WHERE fldTypeName = ''" & sType & "'' AND " & _
" fldCondName = ''" & sCond & "'' AND " & _
" fldCondVar = ''" & sCondVar & "'' AND " & _
" fldCondLBR = ''2L''"
''try to get another recordset via same connection...mayb that the problem?
Set oRsCount = moDb.Execute(sSql)
and thats when i get the errors
I can''t even drop all the wheres'' and get it to work
sSql = "Select Count(*) From " & TABLE_NAME
Try execute sql <Select Count(*) From tblTypeCond>
ErrState: ErrNum 3265 (Item cannot be found in the collection corresponding
to the requested name or ordinal.)
I know i don''t have a field named Count or one named * but I thought that
was a generic function that should run on any table...
do you see what i''m doing wrong?
I spent about 4 hours on google reading tons of posts on Select Count(*) etc
and don''t see what I''m doing wrong.
Thanks
mark
" MP" < no **** @ Thanks.comwrote in message
news:JR ****************** @ tornado.rdc-kc.rr .com ...
"MP" <no****@Thanks.comwrote in message
news:JR******************@tornado.rdc-kc.rr.com...
>
< te ******** @ hotmail.comwrote in message
新闻:11 ********************** @ b28g2000cwb.googlegr oups.com ...
>
<te********@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
您无需取消引用列名称来确定或设置
值。以你的第一个例子:
You don''t need to dereference the column names to determine or set the
value. Taking your first example:
我应该早点尝试过这个...
这个问题不在选择计数声明它是在重复使用
连接...
如果我将计数隔离到它工作的连接上的单个呼叫
sSql =" Select Count(*)From" &安培; TABLE_NAME
FormReport"尝试执行sql<" &安培; sSql& ">"
设置oRs = moDb.Execute(sSql)
lCount2 = oRs.Fields(0).Value
FormReport Lcount2:< &安培; lCount2& ">"
结果:
尝试执行sql<从tblTypeCond选择计数(*)>
Lcount2 :< 37>
所以我想我必须建立多个连接才能获得多个
记录集???
似乎我不能用
设置oRs1 = oConn.Execute(sql1)
而不是ors1.eof
set ors2 = oconn.execute(sql2)
等
ors1.movenext
wend
i我需要像
这样的东西
设置oRs1 = oConn1.Execute(sql1)
设置oConn2 =同一数据库的新连接
而不是ors1.eof
sql2 =基于ors1值
设置ors2 = oconn2.execute(sql2)
等
ors1.movenext
wend
是吗?
谢谢
I should have tried this earlier...
the problem isn''t in the select count statement it''s in reusing the
connection...
if i isolate the count to a single call on the connection it works
sSql = "Select Count(*) From " & TABLE_NAME
FormReport "Try execute sql <" & sSql & ">"
Set oRs = moDb.Execute(sSql)
lCount2 = oRs.Fields(0).Value
FormReport "Lcount2: <" & lCount2 & ">"
result:
Try execute sql <Select Count(*) From tblTypeCond>
Lcount2: <37>
so I guess I have to establish multiple connections to get multiple
recordsets???
seems I cant do
Set oRs1 = oConn.Execute(sql1)
while not ors1.eof
set ors2 = oconn.execute(sql2)
etc
ors1.movenext
wend
i guess i need something like
Set oRs1 = oConn1.Execute(sql1)
Set oConn2 = new connnection to same database
while not ors1.eof
sql2 = based on ors1 values
set ors2 = oconn2.execute(sql2)
etc
ors1.movenext
wend
is that right?
thanks
这篇关于选择计数(*)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!