Re: Load a string of CSV from memory into a dataset

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Sahil, and thank you for the reply.

Unfortunately, I can't do a split on each line using "," as a separator - I
have a field (a description) which could contain commas inside, so that
would create more fields than normal :(
ex: "2,4-DINITROPHENOL" or "DICYCLOHEXYLMETHANE-4,4'-DIISOCYANATE"

I was thinking of splitting by <","> that is using the three characters as
delimiter, but there are numerical values which are not surrounded by double
quotes, like : 33.4, 2,0,0,1, 2.5
So this doesn't work either...

Other ideas ?

Thanks,

Andrei.



"Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx> wrote in message
news:e$H9pbXYFHA.3032@xxxxxxxxxxxxxxxxxxxxxxx
> 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/
>
>
>
> "andrei" <andrei.toma@xxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:#PDYoXWYFHA.3356@xxxxxxxxxxxxxxxxxxxxxxx
> > 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.
> >
> >
>
>


.



Relevant Pages

  • Re: Load a string of CSV from memory into a dataset
    ... you should avoid writing to the disk as ... - which after decryption and just before writing to the CSV ... Then run a foreach on the resulting array and split each line (array ... the csv file is being loaded into a datatable, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Best way to code the following
    ... Its not the reading or writing the CSV file which is the issue it is I cannot find an example of how to place data into a multi-demsendion array and then how to get the data back out of the arral. ...
    (microsoft.public.dotnet.languages.csharp)
  • Read file into array
    ... What are examples of reading a csv file (Comma) into an Array ...
    (comp.lang.ruby)
  • Re: Formatting...
    ... and puts a comma there to show separation. ... "if" statement to search that array and not write it. ... something like if EmailAddr or whatever your using ... Now when I run the script the output is like this: ...
    (microsoft.public.scripting.vbscript)
  • Re: separate cell values with formulas - can this be improved?
    ... It assumes either a comma following the last value, ... first a correction to my original helper column. ... array constant by... ... in the main portion of the invoice I have these two array ...
    (microsoft.public.excel.worksheet.functions)