I am using ADO connection to connect to SQL from Inno setup, I am running some select query which i capture it to a variable, if the select query returns empty rows, it throws “Invalid variant type conversion” error. I am not sure if i can use the VarIsNull option and also how to use it in my code. Please help. Below is the sample code.
ADOCommand := CreateOleObject('ADODB.Command');
ADOCommand.ActiveConnection := ADOConnection;
SQLQuery := 'SELECT Name FROM sys.databases where name=''' + DBValue + '''';
ADOCommand.CommandText := SQLQuery;
ADOCommand.CommandType := adCmdText;
ADORecordset := ADOCommand.Execute;
Name := ADORecordset.Fields(0);
You may check if the returned record set is empty before assigning the value to the Name variable.
A empty recordset will return true for the EOF property just after you open it, in code it may look like this example: