Question : LINQ to SQL insertonsubmit, multiple instances before submitchanges

My code constructed as below writes only 1 record to the database.  What am I doing wrong?

AllItemData is an object, the members of which are two lists.  This code only refers to the first list.  There are 6000+ items in the list, and the code does iterate through all 6000+.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
private void Items_Click(object sender, EventArgs e)
        {
            AllItemData AllItemDatas = this.GetItemData();

            List DataIns = AllItemDatas.ItemData;
            dalDataContext context = new dalDataContext();
            itemTable i = new itemTable();
            foreach (DataIn d in DataIns)
            {
                try
                {
                    i.item_no = d.item_no;

                    context.itemTables.InsertOnSubmit(i);
                }
                catch (Exception ex)
                {
                    //TODO: do something with exeption
                }

            }

            try
            {
                context.SubmitChanges();
            }
            catch (Exception ex)
            {
                //TODO: do something with exception
            }

        }

Answer : LINQ to SQL insertonsubmit, multiple instances before submitchanges

no, just the itemTable line.  You wouldn't want to create a new DataContext for each record.  You only need one instance of the DataContext.
Random Solutions  
 
programming4us programming4us