Re: Storing array of double. There must be an easier way.
From: Miroslav Balaz (miroslav_balaz_at_hotmail.com)
Date: 01/03/05
- Next message: Lionel: "connection open VS2005"
- Previous message: Daud: "SQL Connectivity"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 3 Jan 2005 05:12:49 +0100
Hi,
You can use GetChunk & AppendChunk methods of Field (ADO) object.
How to - see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthgetchunk.asp
Miro Balaz
"David" <David@blackdeck.com> píše v diskusním příspěvku
news:220188C3-5712-4F78-ADA1-242A555DA2B9@microsoft.com...
>I want to create an application that gathers some scientific data and
>stores
> it in an SQL Server database. The application uses C# and ado.net.
>
> I would like to gather a sample of data, which consists of 5,000 doubles.
> Ideally, I would store the data in a single field in a database. One
> record
> stores one collection of data. So it has such fields as time of
> collection,
> settings from the data collection apparatus, and then one field that
> stores
> the collected data.
>
> What's the easiest way to do this?
>
> Because it has 5,000 doubles in the record, it seems like I will have to
> use
> an image field. Not good, because of the overhead, but something I can
> live
> with.
>
> So I have a stored procedure that takes as one of its arguments the data.
> At some point, I have to say something like
> cmd.Parameters["@CollectedData"]=mycollecteddata.
>
> And I think mycollecteddata has to be an ArrayList, right?
>
> Which means I have a variable
>
> double[] orignialcollecteddata.
>
> So I want to convert double[] originalcollecteddata to ArrayList
> mycollecteddata.
>
> At this point, I find myself wishing for C++, which is something I don't
> wish for often. But I wish this because I can't think of anything to do
> except:
>
> mycollecteddata=new ArrayList(40000);
> for (int i=0;i<5000;i++)
> {byte[] onedouble;
> onedouble=System.Bitconverter.GetyBytes(collecteddata[i]);
> for(int j=0;j<8;j++)
> {mycollecteddata[i*8+j]=onedouble[j];
> }
> }
>
> That seems like a whole lot of conversions for what I want to do.
>
> So, in summary, I want to throw an array of doubles into a SQLServer
> database.
>
> The easiest way I can think of to do this is to
>
> 1. Create an arraylist big enough to hold each of the bytes of the array
> of
> doubles.
> 2. For each data point in the original, convert that value into bytes.
> 3. Copy each of the bytes to a corresponding object in the ArrayList.
> 4. Pass the ArrayList to an ado sqlCommand object as an argument that
> will
> be saved in an image file.
>
> It just seems like there ought to be a better way. Is there?
>
> Thanks for any insight into how to store large quantities of floating
> point
> data.
>
- Next message: Lionel: "connection open VS2005"
- Previous message: Daud: "SQL Connectivity"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|