Checking if invoice number exists on sales order invoice entry

SUGGESTED

I have a c# program that automates inputting sales order invoices based on provided xml data. Currently I am setting the batch no and then using,

successCheck(headerObject, (int)headerObject.InvokeMethod("nSetKey", headerInfo["InvoiceNo$"]), "SetKey");

to set the key / invoice no. Currently if I run the code it works fine, everything in input successfully. However, if I run the same invoice data again, all the line items are doubled. I'm wondering if there is a way to check and see if the invoice no already exists in sage, that way I could abort the operation of putting the line items in again, if the same order is accidentally put in twice...Any guidance would be helpful.