Click to See Complete Forum and Search --> : storing arraylist value into a database


solomon_13000
01-14-2007, 12:28 AM
Subscription sub = new Subscription();
sub.groupid = 1;
sub.memberid = 2;
((ArrayList)this.Session["Address"]).Add(sub);


How do I store the values in the arraylist into a database with the table name subscription using the code bellow:

SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "";
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "subscription");

my subscription table consist of 3 fields:

subscriptionid - pk
groupid
memberid

cemaksoy
01-14-2007, 03:31 AM
if you want to save a few subscriptions at one time, why don't you use a while loop and save values with an recordid.For example

Record1:
sub.recordid=1;
sub.groupid = 1;
sub.memberid = 2;

Record2:
sub.recordid=1;
sub.groupid = 2;
sub.memberid = 3;
.
.
.

for n records you can use arraylist bounds in your loop then save all records with recordid ?