Storing array of double. There must be an easier way.
From: David (David_at_blackdeck.com)
Date: 12/17/04
- Next message: Bill Wilkie: "VBA EXCEL DBASE SQL"
- Previous message: William \(Bill\) Vaughn: "Re: Connection pooling..."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 17 Dec 2004 12:29:04 -0800
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: Bill Wilkie: "VBA EXCEL DBASE SQL"
- Previous message: William \(Bill\) Vaughn: "Re: Connection pooling..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|