Arralist on the table

I have an arraylist called backuplist.

this arraylist has structures in it.

So what I need to do is pass this arraylist into a table and then store that table in my SQL database.

Anyone with ideas on what I should do .. ?? Even if this is another way to do it, please let me know.

thank

+2


source to share


4 answers


If you are using VS2008 (tags) you should ideally use List<T>

rather than ArrayList

. You can convert from List<T>

to the DataTable

same way ; then just use SqlDataAdapter

or SqlBulkCopy

to get the data in the database.



+1


source


This is not a complete solution, but I thought I would point you in the right direction. The problem is I don't know your application and your experience is limited so it will be a blow in the dark.

Anyway, here are some resources to help you get 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 the database
http://msdn.microsoft.com/en-us/library/ms233812(VS.80).aspx

0


source


I would settle for using a strongly typed list as Mark suggested. Another possibility to get them into the database would be to plow with foreach (over your list or array) and use the properties of the structure as parameters to the insert stored procedure.

We do this all the time in our application, where we can have a list coming from a business component and tossed to the data layer, where we will go through all the necessary manipulations, and then run our SP update each row.

Let me know if you need a snippet.

-Bob

0


source


I am using ArrayList returned by MySQL, so it is filled with column names and types etc.

ArrayList list = new ArrayList();
// Add Items to list
DataTable table = new DataTable();
table.Load(list);

      

0


source







All Articles