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

LVL 3
Sebastian_OHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ericathomeCommented:
Try the following:

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);
            }

        }

Let me know if this resolves the problem or if the error message changes. Thanks, Eric.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerCommented:
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-1; 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);
            }

        }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.