0

I want to add the 2-dimentional array in the sql server 2000 using c#. But the problem is that there is not array data type in sql. Kindly help me that how can I add the 2-dimentional array in sql server. Thanx for viewing my question...

4 Answers 4

2

A 2-D array is, essentially, a table. So you need to add a table to your database to hold this array. If you need to hold multiple array instance than add an additional column to store a key that will be common to individual arrays.

Sign up to request clarification or add additional context in comments.

Comments

1

You don't need to create an additional column for each dimension as the currently accepted answer says. It's all about serialization.

  1. In SQL Server create a column of type Image to store the n-dimensional array. If you are using SQL server 2005 or superior, use VARBINARY(MAX) instead of Image.
  2. In C#, serialize your n-dimensional array so you can handle it as a 1-dimensional array (byte[])
  3. Save the serialized data into the Image field.

Of course, when you need to fetch the information from the database, you will get a byte array. Then you will need to deserialize that to your orginal type (the n-dimensional array).

Need an example?

Look at this similar question where I posted an example for doing it with a varbinary field. It should be very similar in SQL 2000.

https://stackoverflow.com/a/11334237/354756

Comments

0

Database fields are used for storing single items of data. Any data structures must be mapped to columns and tables in the database - not added to individual database fields.

What sort of data are you storing? If you want to do any kind of indexing or searching of the individiual items of the array then you'd be far better coming up with a database design to reflect the data you're modelling (so an array of cartesian coordinates mgiht map to a table containing x,y and z columns).

If this is to simply store some data for later retrieval then you can add it as a BLOB field and just serialize and deserialize to and from it.

Comments

0

Don't know what you are trying to accomplish since you are not giving any details but take a look at Arrays and Lists in SQL Server 2005 or Arrays and Lists in SQL Server (SQL 2000 and Earlier)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.