listbox values to database
<p>I have two list boxes. I am able to add values to one listbox through a textbox. From this listbox i add the desired values to listbox2 by clicking the add button.</p>

<p>Now i am not able to get how to add the values from the second listbox to a database table called Machines. these values get added to different rows.</p>

<pre>
Listbox2

PC1 

PC2

PC3
</pre>

<p>and add these to database table Machines</p>

<p>Please help me out</p>

<p>This is the code for passing values from one listbox to other...</p>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;
using System.IO;

namespace WebApplication3
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        ArrayList lasset = new ArrayList();
        ArrayList lsubordinate = new ArrayList();
        static ArrayList UpdateList = new ArrayList();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        //add one by one//
        protected void Button4_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex &gt;= 0)
            {
                for (int i = 0; i &lt; ListBox1.Items.Count; i++)
                {
                    if (ListBox1.Items[i].Selected)
                    {
                        if (!lasset.Contains(ListBox1.Items[i]))
                        {
                            lasset.Add(ListBox1.Items[i]);
                        }
                    }
                }
                for (int i = 0; i &lt; lasset.Count; i++)
                {
                    if (!ListBox2.Items.Contains(((ListItem)lasset[i])))
                    {
                        ListBox2.Items.Add(((ListItem)lasset[i]));
                    }
                    ListBox1.Items.Remove(((ListItem)lasset[i]));
                }
            }
        }
        //Add all
        protected void Button5_Click(object sender, EventArgs e)
        {
            while (ListBox1.Items.Count != 0)
            {
                for (int i = 0; i &lt; ListBox1.Items.Count; i++)
                {
                    if (!lasset.Contains(ListBox1.Items[i]))
                    {
                        lasset.Add(ListBox1.Items[i]);
                    }
                }
                for (int i = 0; i &lt; lasset.Count; i++)
                {
                    if (!ListBox2.Items.Contains(((ListItem)lasset[i])))
                    {
                        ListBox2.Items.Add(((ListItem)lasset[i]));
                    }
                    ListBox1.Items.Remove(((ListItem)lasset[i]));
                }
            }
                    }
        //remove from listbox2 and add to listbox1//
        protected void Button6_Click(object sender, EventArgs e)
        {
            if (ListBox2.SelectedItem != null)
            {
                for (int i = 0; i &lt; ListBox2.Items.Count; i++)
                {
                    if (ListBox2.Items[i].Selected)
                    {
                        if (!lsubordinate.Contains(ListBox2.Items[i]))
                        {
                            lsubordinate.Add(ListBox2.Items[i]);
                        }
                    }
                }
                for (int i = 0; i &lt; lsubordinate.Count; i++)
                {
                    if (!ListBox1.Items.Contains(((ListItem)lsubordinate[i])))
                    {
                        ListBox1.Items.Add(((ListItem)lsubordinate[i]));
                    }
                    ListBox2.Items.Remove(((ListItem)lsubordinate[i]));
                    UpdateList.Add(lsubordinate[i]);
                }
            }

        }
        //remove all
        protected void Button7_Click(object sender, EventArgs e)
        {
            while (ListBox2.Items.Count != 0)
            {
                for (int i = 0; i &lt; ListBox2.Items.Count; i++)
                {
                    if (!lsubordinate.Contains(ListBox2.Items[i]))
                    {
                        lsubordinate.Add(ListBox2.Items[i]);
                    }
                }
                for (int i = 0; i &lt; lsubordinate.Count; i++)
                {
                    if (!ListBox1.Items.Contains(((ListItem)lsubordinate[i])))
                    {
                        ListBox1.Items.Add(((ListItem)lsubordinate[i]));
                    }
                    ListBox2.Items.Remove(((ListItem)lsubordinate[i]));
                    UpdateList.Add(lsubordinate[i]);
                }
            }
        }
</code></pre>
