Link to home
Start Free TrialLog in
Avatar of Sebastian_OH
Sebastian_OH

asked on

Problem inserting Data to Database in ASP.Net c#

Hi,

i try to insert every item from a class into a database.
When i run the program, the Data shows up in SQL, but the application throws the following exception:

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

What can i do to fix it?
protected void btnCheckout_Click(object sender, EventArgs e)
        {
            ADDTest.Datasets.dsCribstoreTableAdapters.CheckoutTableAdapter dsCheckout = new ADDTest.Datasets.dsCribstoreTableAdapters.CheckoutTableAdapter();
            int intItems = ShoppingCart.Instance.Items.Count;
            for (int i = 0; i <= intItems; i++)
            {
                dsCheckout.Insert((string)ShoppingCart.Instance.Items[i].USer,(string)ShoppingCart.Instance.Items[i].ProductId,(int)ShoppingCart.Instance.Items[i].Quantity,(string)ShoppingCart.Instance.Items[i].ChrgDepartment,null,DateTime.Now);
            }

        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ericathome
ericathome
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Ashok
Ashok
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial