Save double array to sql server 2008

Hi!

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?

LVL 1
AWestEngAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

momi_sabagCommented:
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
0
cyberkiwiCommented:
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?
0
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
0
cyberkiwiCommented:
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;" + 
                                       "database=dbname;");
myConnection.Open();
SqlCommand  myCommand = new SqlCommand(
@"insert mytable (doublearrayasxml) values ('" + xmlStr + "')", myConnection);
myCommand.ExecuteNonQuery();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.