Multidimensional list or array in C#


I have a collection of data from a db like this:


I want to put this in a multidimensional list or array(but I do not know the number of records), and then to display the data in a grid view!

Please help me,
Thank you.
Qw MAsked:
Who is Participating?
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.

Peter HutchisonSenior Network Systems SpecialistCommented:
You do need to specify the max number of records when declaring an array and arrays can only be of a certain type e.g. int, char etc.
When declaring an array esp. char or string arrays, you also need to take into consideration the string length e.g.

char myarray[100][100][25] = { {"Mike", "insert", "2013-01-02"}, {"John", "update", "2013-01-15"} , {"Mike", "update", "2013-01-03"}} ;
Qw MAuthor Commented:
And if I want to add to myarray vector another set of records like:
Vlad,update,2013-01-09 how can I do it. Can you write me the code!

Than you!
Fernando SotoRetiredCommented:
Hi cristianosx;

Not sure what type of object the following data is in a List, Array or File on disk


But if you create a class to populate it with the data as follows

public class MyData
    public string Name { get; set; }
    public string Type { get; set; }
    public string UpdatedOn { get; set; }

Open in new window

You can create a List of MyData As follows

List<MyData> listData = new List<MyData>();

each row of the data filling one class then you do not need to know how many rows are in the input data and you can assign the List<MyData> to the DataSource of the DataGridView and have it display.

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
käµfm³d 👽Commented:
You do need to specify the max number of records when declaring an array
Well, you could repeatedly create a new array sized one larger than the previous, and then copy from the old to the new, but that gets messy. List would definitely be more "user" friendly.

When declaring an array esp. char or string arrays, you also need to take into consideration the string length e.g.
Character arrays, yes; string arrays, no.
I may suggest you to use a simple DataTable to store your db results.
It would be very simple, just get the "select" result as a DataTable with something like:
DataTable dt = null;
using (SqlDataAdapter da = new SqlDataAdapter(mySQLCommand))
   dt = new DataTable(mySQLCommand.CommandText);

Open in new window

Else, you can create a Class (as suggested by #FernandoSoto) and a "List" Class of that type. You can fill it with as many items you need and (in my opinion) is the best way to manage typed data from a db.
You can refer to this article for a more detailed description of what I mean:
Please note that in this article it is described how to "serialize/deserialize" an Entity (a Class). You may need only a part of it, where it is showed how to create BaseEntity and BaseEntityList classes. Do it once and you get a simpler way to work...

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

From novice to tech pro — start learning today.