Domanda

I can find each piece of this problem, but they don't work together. Multiple record sets work fine when passing a sql string to Recordset.Open, but once you upgrade to an ADODB.Command, neither Command.Execute nor Recordset.Open will return more than the first recordset from a provided command. Contrariwise, I can find no way to use a parameterized query without relying on Command in some way.

Here's all I have for my SQL code:

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

The declare appears to be counting as a recordset, so I'm unable to get any info past that. I'm hesitant to put this in a stored procedure because it contributes to proliferation, but if that's the only way I'll do it.

È stato utile?

Soluzione

Here is a basic example, the magic line is;

Set rs = rs.NextRecordSet

Pseudo coded so apologies if there are some typos.

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top