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
source to share
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.
source to share
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
source to share
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
source to share