Automating QTP Test Automation Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map
SQL Function - DeleteThis function deletes an entry from the database. Download it Here (right-click and then save target as). (NOTE - you can just cut & paste from below, but the formatting will have multiple spaces instead of tabs).
'=========================================================================
Function zSql_Delete(sDsn, sTableName, sIdFieldName, sIdFieldValue) 'This function is for deleting a single entry in a database 'Ideally the field referenced should be the primary key 'The function will abort if nothing is found 'For SAFETY the function will abort if more than one entry is found Dim sSql sSql = "SELECT * FROM " & sTableName & " WHERE " & sIdFieldName & " = " & sIdFieldValue iCount = zSql_CountRows(sDsn,sSql) If iCount = 1 Then sSql = "DELETE FROM " & sTableName & " WHERE " & sIdFieldName & " = " & sIdFieldValue Call SqlExecute(sDsn, sSql) zSql_Delete = True ElseIf iCount = 0 Then print "Nothing found to delete" zSql_Delete = False Else print "More than one row found - aborting delete" zSql_Delete = False End If '========================================================================= |