I would advice you to debug the script and find out at what line it throws
the error. Add watch for your variables to see if they are having values as
expected at runtime.
Learning more on datatable and ADODB would definitely help but learning how
to debug the code is more important of all.
QTP help is the best source of knowledge (and google of course).
Coming back to your code, can you send the exact error message? Creating
multiple runtime sheets should work fine as I did in below code (somewhat
similar to what you have. I replaced recordset loop with a simple FOR loop
for demo purpose):
For cnt=1 to 3 '<-- 3 sheets will be created at runtime
''create runtime sheet and its parameters
Set var_AddSheet = DataTable.AddSheet("Testing" & cnt)
For i =1 to 10 '<-- instead of recordset fields
var_AddSheet.AddParameter "Col_" & cnt & "" & i,""
Next
''populate the runtime sheet
For i=1 to 10 '<-- loop through recordset rows
DataTable.GetSheet(var_AddSheet.name).SetCurrentRow(i)
For j=1 to 10 '<--- loop through recordset fields
DataTable("Col_" & cnt & "" & j, var_AddSheet.name)="value_"
& j
Next
Next
Next
On Mon, Jan 24, 2011 at 2:12 AM, Jimmie Parson <[email protected]> wrote:
> Mukesh,
>
> I did as you suggested and that works wonderfully as long as I have
> only one new sheet created. On some tests I am required to connect to
> the DB and run multiple scripts which create additional "output"
> sheets i.e. "output1", "output2". When I try to return the data from
> the additional sheets I get the error stating the parameter does not
> exist. I guess my lack of programming knowledge is coming back to bite
> me again. So the additional questions I have are:
>
> 1. I am assuming it is possible to return the data from those
> additional sheets and that I just do not know how. Is the problem just
> a minor difference from my original post or is my approach faulty?
>
> 2. I am just duplicating the code I originally posted to create the
> additional sheets. If this is incorrect can anyone give me a pointer
> to a resource to learn more about using the database connection and
> runtime datatables.
>
> I am posting the code as below as to how I am using it any further
> suggestions are greatly appreciated.
>
> Once again Mukesh thank you for the intial code change it has
> simplified things a great deal.
>
> 'Connect to Oracle DB and return Customer Information via SQL
> Statement, then write the data to
> 'the QTP runtime data table.
>
> Dim adocon,adorecordset
> Set adocon=CreateObject("ADODB.Connection")
> constr="Provider=OraOLEDB.Oracle.1;Password=XXXX;Persist Security
> Info=True;User ID=XXXX;Data Source=Dev"
> adocon.Open constr
> Set adorecordset=CreateObject("ADODB.Recordset")
> Set adorecordset.ActiveConnection=adocon
> Strsql="Select 'TEST PRICE LIST:' || to_char(sysdate,' MM-DD-YY
> HH:MM:SS') as PRICE_LST_NAME from Dual"
> adorecordset.Source=Strsql
> adorecordset.Open
> set outsheet=Datatable.Addsheet("output")
> For each fld in adoRecordset.Fields
> outsheet.AddParameter fld.name,""
> Next
> i=1
> Do while Not adorecordset.EOF
> DataTable.GetSheet(outsheet.name).SetCurrentRow(i)
> For each fld in adorecordset.Fields
> outsheet.GetParameter(fld.name).value=fld.value
> Next
> adorecordset.MoveNext
> i=i+1
> Loop
>
>
> 'close the recordset object
> adorecordset.close
> 'Destroy the recordset object
> Set adorecordset = nothing
>
>
> 'close the database connection
> adoCon.close
> 'Destroy the connection object
> Set adoCon = nothing
>
> 'Connect to Oracle DB and return Item Information via SQL Statement,
> then write the data to
> 'the QTP runtime datatable.
>
>
> Set adocon=CreateObject("ADODB.Connection")
> constr="Provider=OraOLEDB.Oracle.1;Password=XXXX;Persist Security
> Info=True;User ID=XXXX;Data Source=Dev"
> adocon.Open constr
> Set adorecordset=CreateObject("ADODB.Recordset")
> Set adorecordset.ActiveConnection=adocon
> Strsql="SELECT Segment1, Quantity FROM Item_Master"
> adorecordset.Source=Strsql
> adorecordset.Open
> set outsheet=Datatable.Addsheet("output1")
> For each fld in adoRecordset.Fields
> outsheet.AddParameter fld.name,""
> Next
> i=1
> Do while Not adorecordset.EOF
> DataTable.GetSheet(outsheet.name).SetCurrentRow(i)
> For each fld in adorecordset.Fields
> outsheet.GetParameter(fld.name).value=fld.value
> Next
> adorecordset.MoveNext
> i=i+1
> Loop
>
>
> 'close the recordset object
> adorecordset.close
> 'Destroy the recordset object
> Set adorecordset = nothing
>
> 'close the database connection
> adoCon.close
> 'Destroy the connection object
> Set adoCon = nothing
>
>
>
> Mukesh Takhtani wrote:
> > Jimmie,
> >
> > Replace your below lines of code:
> > Do while Not adorecordset.EOF
> > DataTable.SetCurrentRow(i)
> >
> > , with this one :
> > Do while Not adorecordset.EOF
> > DataTable.GetSheet(outsheet.name).SetCurrentRow(i)
> >
> > Thanks,
> > Mukesh
> >
> > On Sat, Jan 22, 2011 at 1:59 AM, Jimmie Parson <[email protected]>
> wrote:
> >
> > > To all,
> > >
> > > I need to know if it is possible to use data from the runtime data
> > > sheet in its current test?
> > >
> > > The example is as follows:
> > >
> > > 1. A new sheet is created in runtime datasheet with a script and
> > > called "output".
> > >
> > > 2. The script takes the columns names and inserts them as the "output"
> > > parameters.
> > >
> > > 3. I want to use the values in the "output" sheet in the test. I have
> > > tried all the ways I can find that reference the global and local
> > > datasheets but have not found anyway to use the data from the created
> > > sheet "output"
> > >
> > > I will include the code I am using to retrieve the data for the
> > > runtime datatable.
> > >
> > > Dim adocon,adorecordset
> > > Set adocon=CreateObject("ADODB.Connection")
> > > constr="Provider=OraOLEDB.Oracle.1;Password=XXXX;Persist Security
> > > Info=True;User ID=XXXX;Data Source=Dev"
> > > adocon.Open constr
> > > Set adorecordset=CreateObject("ADODB.Recordset")
> > > Set adorecordset.ActiveConnection=adocon
> > > Strsql="Select 'TEST PRICE LIST:' || to_char(sysdate,' MM-DD-YY
> > > HH:MM:SS') as PRICE_LST_NAME from Dual"
> > > adorecordset.Source=Strsql
> > > adorecordset.Open
> > > set outsheet=Datatable.Addsheet("output")
> > > For each fld in adoRecordset.Fields
> > > outsheet.AddParameter fld.name,""
> > > Next
> > > i=1
> > > Do while Not adorecordset.EOF
> > > DataTable.SetCurrentRow(i)
> > > For each fld in adorecordset.Fields
> > > outsheet.GetParameter(fld.name).value=fld.value
> > > Next
> > > adorecordset.MoveNext
> > > i=i+1
> > > Loop
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> > > "QTP - HP Quick Test Professional - Automated Software Testing"
> > > group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<mercuryqtp%[email protected]>
> <mercuryqtp%[email protected]<mercuryqtp%[email protected]>
> >
> > > For more options, visit this group at
> > > http://groups.google.com/group/MercuryQTP?hl=en
> >
> >
> >
> >
> > --
> > Mukesh Takhtani
>
> --
> You received this message because you are subscribed to the Google
> "QTP - HP Quick Test Professional - Automated Software Testing"
> group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<mercuryqtp%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/MercuryQTP?hl=en
>
--
Mukesh Takhtani
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en