1

ASP VBscript から SQL Server 2008 R2 をクエリするときに、結果セットからレコード数を取得したいと考えています。

Conn = "Provider=SQLNCLI10; DataTypeCompatibility=80; Data Source=Source; Initial Catalog=catalog; User ID=id; Password=pw; Network Library=dbmssocn; Encrypt=Yes;"

これは正しいレコード数を返します:

consulta = "select 'x' x;"

rs.open consulta, Conexao, 3
Response.Write(rs.RecordCount)

しかし、一時テーブルから選択すると、エラーがスローされます。

consulta = "select 'x' x into #t; select * from #t; drop table #t;"

rs.open consulta, Conexao, 3
Response.Write(rs.RecordCount)

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.
4

2 に答える 2

3

私はあなたが使用する必要があると思います.NextRecordSet()

strsql = "select 'x' x into #t; select * from #t; drop table #t;"

rs.Open strsql, conn

'Move to your 2nd recordset to return the values (in this case 'x')
Set rs = rs.NextRecordset()
if not rs.eof then
    response.write rs(0)
end if
rs.close

これは、SQL文字列を分離して使用するEXECUTE場合、またはOPEN必要に応じて使用する場合にも機能します。

'Create Temp Table 
strsql = "select 'x' x into #t; "
conn.execute strsql

'Select From Temp Table
strsql = "select * from #t;"
rs.open strsql, conn
if not rs.eof then
    response.write rs(0)
end if
rs.close

'Drop Temp Table
strsql = "drop table #t;"
conn.execute strsql

お役に立てれば。

于 2013-02-18T15:21:18.913 に答える