This topic is locked
[SOLVED]

 File Import

5/23/2016 6:14:32 PM
ASPRunner.NET General questions
jadach authorDevClub member

I need a way to import data to a table every 2 weeks. This data is a refresh of existing data. What I am trying to do is delete all records from the table prior to inserting new. The import will be under 500 records and about 12 fields. I can easily do this manually, but want to allow the system admin to take care of it through import data.
Thanks

admin 5/24/2016

I guess you can use BeforeImport event ( http://xlinesoft.com/asprunnernet/docs/before_import_started.htm ) and here is the sample code:

tDAL.CustomQuery("delete from SomeTable");
Pete K 5/24/2016

Isn't it better to use truncate table rather than delete from table? I know this is true if you are using an identity field for the PK.

jadach authorDevClub member 5/24/2016

Thanks Peter. I tried that approach and nothing was deleted.

Pete K 5/26/2016



Thanks Peter. I tried that approach and nothing was deleted.


That's interesting. I've never had any trouble with truncate. It's much faster than delete if you want to clear out a table completely and what I really like is if you have an auto identity PK, it gets reset with truncate.

jadach authorDevClub member 5/26/2016

Ok, here was my problem. I tried using this on before import started and it did nothing.
dynamic tblProductivity = GlobalVars.dal.Table("Productivity");

tblProductivity.Delete();
I then used:
tDAL.CustomQuery("delete from Productivity");
and it worked as expected.
Thanks for the help all.
Peter, I may be wrong, but I think special permissions need to be granted to the SQL user to truncate. However, I do agree it's better due to the PK as you mentioned..