Save double array to sql server 2008


I need some tips how I should save a double array in my sql server 2008 database

So if I have a double array with 50 000 positions I like to insert this data to a column in my table, any tips?

Who is Participating?
cyberkiwiConnect With a Mentor Commented:
Here's one way to do it

double[] dbar = new double[10] { 1,2,3,5,6,8,123,12,32,33 };
string xmlStr = "<DoubleArray>";
foreach (double d in dbar)
    xmlStr += "<Double>" + d.ToString() + "</Double>";
xmlStr += "</DoubleArray>";

SqlConnection myConnection = new SqlConnection("Integrated Security=SSPI;" + 
                                       "server=servername;" + 
SqlCommand  myCommand = new SqlCommand(
@"insert mytable (doublearrayasxml) values ('" + xmlStr + "')", myConnection);

Open in new window

do you need to be able to access each position or would you select and update all positions every time?
if you need specific access, i would create a table like
row, col, value
that will have 50000 rows
if you need all the values each time, i would store it as xml or binary value
Do you mean as a column in a single record?
XML is a pretty good means of storing that, SQL will support querying by XPath when you need the data again.
If you mean 50,000 rows, then split it into two columns, so you have your db record/col = array[dim1,dim2]

Or are you after C# code?
AWestEngAuthor Commented:
I like to save all data in one row and one column in the database, so xml sounds fine
the array is 1-Dimension [x1,x2,x3,x4]
Yes, I need help with some C# code to do this
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.