static void qrTest(Args _args)
{
QueryRun qr;
Query q;
CustTable cust;
;
q = new Query();
q.addDataSource(tableNum(custtable));
qr = new QueryRun(q);
//First prompt
if(qr.prompt())
{
while(qr.next())
{
cust = qr.get(tableNum(custTable));
print cust.AccountNum;
}
}
//Second prompt
qr.reset();
if(qr.prompt())
{
while(qr.next())
{
cust = qr.get(tableNum(custTable));
print cust.AccountNum;
}
}
pause;
}
{
QueryRun qr;
Query q;
CustTable cust;
;
q = new Query();
q.addDataSource(tableNum(custtable));
qr = new QueryRun(q);
//First prompt
if(qr.prompt())
{
while(qr.next())
{
cust = qr.get(tableNum(custTable));
print cust.AccountNum;
}
}
//Second prompt
qr.reset();
if(qr.prompt())
{
while(qr.next())
{
cust = qr.get(tableNum(custTable));
print cust.AccountNum;
}
}
pause;
}
重点也就在//second prompt后面的那句qr.reset()了.
试着将该函数解释如下:
Reset():
将QueryRun对象qr的查询结果清零,游标(或者称为数据指针)指向初始位置,这样保证在下次运行qr.Next()时,重新执行SQL查询,获取新的数据集,在查询完毕后,游标指向返回结果集的第一条记录.
如果想让一个QueryRun对象执行多次数据库查询,必须让让游标指向初始位置,这样qr在下次执行next()函数的时候才会知道要执行一次新的查询以便更新结果集,否则qr将不再执行新的查询动作.