Forum Discussion
sastowe
14 years agoSuper Contributor
There is no method of "copying" the data that I know of. You need to open the connection, recordset, loop and create the data table.
So a simple untested psydo code example would be:
' create a table var
If Project.Variables.VariableExists("Person") then
Project.Variables.RemoveVariable "Person"
end if
Project.Variables.AddVariable "Person", "Table"
set s = Project.Variables.VariableByName("Person")
s.AddColumn "FirstName"
s.AddColumn "LastName"
' open a recordset
set cn = Sys.OleObject("ADODB.Connection")
set rs = Sys.OleObject("ADODB.Recordset")
cn.Open ... connection string...
sSql = "Select Count(*) FROM ".... ' get the count of the records gonna return. Where clause... whatever
rs.Open, sSql, cn, adOpenForwardOnly
iRecordCount = rs(0)
rs.Close
sSql = "Select FirstName, LastName " ' actually select the records same where claus...
set rs = Sys.OleObject("ADODB.Recordset")
rs.Open, sSql, cn, adOpenForwardOnly
s.RowCount = iRecordCount
i = 0
Do While Not rs.Eof
s.FirstName(i) = rs("FirstName").Value
s.LastName(i) = rs("LastName").Value
rs.MoveNext
i = i + 1
Loop
rs.close
cn.close
Error trapping, and all the other stuff left as an exercise to the reader! Good luck.
So a simple untested psydo code example would be:
' create a table var
If Project.Variables.VariableExists("Person") then
Project.Variables.RemoveVariable "Person"
end if
Project.Variables.AddVariable "Person", "Table"
set s = Project.Variables.VariableByName("Person")
s.AddColumn "FirstName"
s.AddColumn "LastName"
' open a recordset
set cn = Sys.OleObject("ADODB.Connection")
set rs = Sys.OleObject("ADODB.Recordset")
cn.Open ... connection string...
sSql = "Select Count(*) FROM ".... ' get the count of the records gonna return. Where clause... whatever
rs.Open, sSql, cn, adOpenForwardOnly
iRecordCount = rs(0)
rs.Close
sSql = "Select FirstName, LastName " ' actually select the records same where claus...
set rs = Sys.OleObject("ADODB.Recordset")
rs.Open, sSql, cn, adOpenForwardOnly
s.RowCount = iRecordCount
i = 0
Do While Not rs.Eof
s.FirstName(i) = rs("FirstName").Value
s.LastName(i) = rs("LastName").Value
rs.MoveNext
i = i + 1
Loop
rs.close
cn.close
Error trapping, and all the other stuff left as an exercise to the reader! Good luck.