views:

96

answers:

4

I have an arraylist called backuplist.

this arraylist has structures in it.

So what i need to do is transfer this arraylist in a table and then store this table in my SQL database.

Anybody with ideas as to what i should do..?? Even if it is a different way to do this please let me know.

Thanks

A: 

This isn't a complete solution, but I thought I'd point you in the right direction. The problem is I don't really know your application, and your experience is limited, so it's going to be a stab in the dark.

Anyway, here are a couple of resources to get you started:

Converting Custom Collections To and From DataTable
http://blog.lozanotek.com/archive/2007/05/09/Converting_Custom_Collections_To_and_From_DataTable.aspx

Inserting New Records into a Database
http://msdn.microsoft.com/en-us/library/ms233812(VS.80).aspx

Robert Harvey
A: 

modelshredder has got what you need.

Johannes Rudolph
+1  A: 

If you are using VS2008 (tags), you should ideally use List<T>, not ArrayList. You can convert from a List<T> to a DataTable like so; then just use a SqlDataAdapter or SqlBulkCopy to get the data into the database.

Marc Gravell
True, my first impression : he is using .NET 1.1 but the tags say otherwise
CRice
A: 

I'd agree on using a strongly typed list as Marc suggested. Another option to getting those into the database would be to plow through with a foreach (on either your list or array), and use the structure properties as parameters to an insert stored procedure.

We do this all the time in our app, where we might have a List coming from a business component and being tossed to the data layer, where we'll loop through, do any necesary manipulation, then run our update SP on each row.

Let me know if you need a snippet.

-Bob

Bob Palmer