Load a string of CSV from memory into a dataset

  • Thread starter Thread starter andrei
  • Start date Start date
A

andrei

Hi Group,

Here is what I'm trying to do in my application:
1. the customer uploads an encrypted file to the server (it's a ASP.NET
application)
2. the uploaded file is decrypted to a comma separated list of values
3. the list is being written to a CSV file
4. the csv file is being loaded into a datatable, using OleDbDataAdapter
5. the recordset, after some checking and validation, is being written to a
SQL database.

Question:

Is it possible to skip somehow the steps where I'm writing the comma
separated list to a csv file and then reloading the list into a datatable?
Something like loading the datatable directly from the comma separated
string **in memory** ?

Many thanks !

Andrei.
 
Yes there is. As a matter of fact, you should avoid writing to the disk as
that is hella slow.

What you can do however is that the "Stream" you get - (is it
MemoryStream?) - which after decryption and just before writing to the CSV
file - subject that to a "StreamReader" - to get a string out of it.

Great, now that you have a CSV'ed string out of it, split the string for New
lines.
Then run a foreach on the resulting array and split each line (array
element) using the "," character.
For each sub array element - create an object array - and do a
DataTable.LoadDataRow(passinthearray,true).

Thats it. Problem solved.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/
 
Back
Top