2014-04-16 4 views
1

이 문제의 각 부분을 찾을 수는 있지만 함께 작동하지는 않습니다. Recordset.Open에 SQL 문자열을 전달할 때 여러 레코드 집합이 제대로 작동하지만 ADODB.Command로 업그레이드 한 후에는 Command.Execute와 Recordset.Open이 제공된 명령에서 첫 번째 레코드 집합 이상을 반환하지 않습니다. 반대로 Command에 의존하지 않고 매개 변수화 된 쿼리를 사용할 방법이 없습니다.ASP에서 매개 변수화 된 쿼리에서 여러 레코드 집합을 반환하려면 어떻게해야합니까?

declare @var int 
select @var = column from table where othercolumn = ? 
(other stuff with @var) 

선언은 레코드로 계산 것으로 보인다, 그래서 나는 과거의 어떤 정보를 얻을 수 없어요 :

여기 내 SQL 코드가 전부입니다. 나는 이것이 확산에 기여하기 때문에 이것을 스토어드 프로 시저에 넣는 것을 주저하고 있지만, 이것이 그렇게 할 수있는 유일한 방법이라면.

+0

SQL에서 SET NOCOUNT ON;을 사용하여 닫힌 레코드 세트 강제로 행 수를 중지하십시오. 또는'Set rs = cmd.Execute()'와 같은 것을 사용할 때'Set rs = rs.NextRecordSet'을 사용하여 다중 레코드 셋 쿼리에서 다음 레코드를 얻습니다. – Lankymart

답변

1

여기에 기본 예가 있습니다.

Set rs = rs.NextRecordSet 

몇 가지 오타가있는 경우 의사가 표시됩니다.

Dim cmd, rs, sql, connstring 

Set cmd = Server.CreateObject("ADODB.Command") 

connstring = "your connection string here" 

sql = "" 
sql = sql & "SELECT col1, col2 FROM table1 WHERE col0 = ?" & vbCrLf 
sql = sql & "SELECT col1, col2 FROM table2 WHERE col0 = ?" 

With cmd 
    .ActiveConnection = connstring 
    .CommandType = adCmdText 
    .CommandText = sql 
    .Parameters.Append(.CreateParameter("@table1id", adInteger, adParamInput, 4)) 
    .Parameters.Append(.CreateParameter("@table2id", adInteger, adParamInput, 4)) 
    'Return first Recordset for table1 
    'id1 and id2 contain your values to pass in your parameters. 
    Set rs = .Execute(, Array(id1, id2)) 
    'Do something with your data, use .GetRows() to return an array or something 
    'Then return your second Recordset for table2 
    Set rs = rs.NextRecordSet 
    'Do something with your data, use .GetRows() to return an array or something 
    Call rs.Close() 
    Set rs = Nothing 
End With 
'Bit of cleanup 
Set cmd = Nothing