Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into database from array

Status
Not open for further replies.

JonoB

Programmer
May 29, 2003
147
0
0
GB
Hi all,

I am parsing a relatively large text file, and I need to split the information into various fields, and then insert the parsed data into a database.

At the moment, I have the parsing bit working fine, and I create an array to temporarily hold all the information - this is a 2-dimension array of 10 columns and about 150,000 rows (although this can vary).

Whats the easiest way for me to insert the data into the database (at the moment I am using sql server compact)? I am hoping that I dont have to loop through the array, and that I can do some kind of bulk insert.

I'm (very) new to vb (coming from a vba background though), so please go easy on me! With VBA, I would probably use an ADO recordset, but I am guessing (wildly!) that some form of SqlCeResultset may be needed in this case - am I at least on the right track?

Specs:
Windows XP
Visual Basic express 2008
Sql Server Compact 3.5

Thanks in advance.
 
You're going to have to spool the array. If i were doing this, i would create a data struct, and load a collection with all the structs then spool the collection, and insert all the rows into the database.

I cannot think of a way to get around spooling the collection/array to load the database. I have something similar that runs once a week.

it's not bad, you just start it and walk away.

You will have to watch out for malformed data, and start and end conditions on your reading the file. Also, you are going to have to have some "fuzzy" handling on the insert into the database, in case you come across a timeout or something similar.

-Sometimes the answer to your question is the hack that works
 
So, if I understand you correctly, I use a collection to hold the data, and I then loop through the collection and insert one record at a time into the database?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top