ilija_panov
13 years agoContributor
How to test in script if an ADO RecordSet object has returned records or not ?
Hi Everyone,
I have the following procedure which should check if records in a table have been inserted for a given date with a simple query (
select 1 as inserted from dbo.ExchangeRates where ValidDate = '2012-09-05' ):
function ratesInserted(date)
{
var Cmd, RecSet, Prm;
Cmd = ADO.CreateCommand();
Cmd.ActiveConnection = connectCWN();
// Specify command type and text
Cmd.CommandType = adCmdText;
Cmd.CommandText = "select 1 as inserted from dbo.ExchangeRates where (ValidDate = ?)";
// Create accountnum parameter
Prm = Cmd.CreateParameter("@ValidDate",adVarChar, adParamInput);
// Specify the parameter value
Prm.Size = 30;
Prm.Value = date;
Cmd.Parameters.Append(Prm);
// Execute the command
RecSet = Cmd.Execute();
if (!RecSet.Fields(0).Value.Exists)
{
Log.Message("false");
return "false";
}
else
{
Log.Message("true");
return "true";
}
Cmd.ActiveConnection.Close();
}
The problems is that the RecSet always alsways has a property RecSet.Exists = true whether it returns an empty data set or not which is what I need to check in the if condition.
If using !RecSet.Fields(0).Value.Exists or !RecSet.Fields(0).Value == null it fails when the RecSet is empty because there is no BOF EOF
Third attempt was to use the RecSet.BOF property but this is alwayds treue as well . which is kind of weird and in contradiction to the above
I would really appreciate if you can help me out which property or method of RecSet to use in order to check if it returns a data set .
Best Regards,
Ilija
I have the following procedure which should check if records in a table have been inserted for a given date with a simple query (
select 1 as inserted from dbo.ExchangeRates where ValidDate = '2012-09-05' ):
function ratesInserted(date)
{
var Cmd, RecSet, Prm;
Cmd = ADO.CreateCommand();
Cmd.ActiveConnection = connectCWN();
// Specify command type and text
Cmd.CommandType = adCmdText;
Cmd.CommandText = "select 1 as inserted from dbo.ExchangeRates where (ValidDate = ?)";
// Create accountnum parameter
Prm = Cmd.CreateParameter("@ValidDate",adVarChar, adParamInput);
// Specify the parameter value
Prm.Size = 30;
Prm.Value = date;
Cmd.Parameters.Append(Prm);
// Execute the command
RecSet = Cmd.Execute();
if (!RecSet.Fields(0).Value.Exists)
{
Log.Message("false");
return "false";
}
else
{
Log.Message("true");
return "true";
}
Cmd.ActiveConnection.Close();
}
The problems is that the RecSet always alsways has a property RecSet.Exists = true whether it returns an empty data set or not which is what I need to check in the if condition.
If using !RecSet.Fields(0).Value.Exists or !RecSet.Fields(0).Value == null it fails when the RecSet is empty because there is no BOF EOF
Third attempt was to use the RecSet.BOF property but this is alwayds treue as well . which is kind of weird and in contradiction to the above
I would really appreciate if you can help me out which property or method of RecSet to use in order to check if it returns a data set .
Best Regards,
Ilija