Click here to Skip to main content
13,192,855 members (55,074 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
string productids = string.Empty;
            DataTable dt;
 
            if (Session["MyCart"] != null)
            {
                dt = (DataTable)Session["MyCart"];
 
                tkbsonsmerchant k = new tkbsonsmerchant()
                {
                    CustomerName = txtCustomerName.Text,
                    CustomerEmailID = txtCustomerEmailID.Text,
                    CustomerAddress = txtCustomerAddress.Text,
                    CustomerPhoneNo = txtCustomerPhoneNo.Text,
                    TotalPrice = Convert.ToInt32(txtTotalPrice.Text),
                    ProductList = productids,
                    PaymentMethod = rblPaymentMethod.SelectedItem.Text
                };
 
                DataTable dtResult = k.SaveCustomerDetails();
 

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    tkbsonsmerchant SaveProducts = new tkbsonsmerchant()
                    {
                        
  //BELOW LIEN HERE IS ERROR CAME  -  INDEX OUT OF RANGE EXCEPTION WAS UNHANDLED BY USER CODE - THERE IS ROW AT POSITION 0.
                      CustomerID = Convert.ToInt32(dtResult.Rows[0][0]),
                        ProductID = Convert.ToInt32(dt.Rows[i]["ProductID"]),
                    };
                    SaveProducts.SaveCustomerProducts();
                }
 
                Session.Clear();
 

 
                lblTransactionNo.Text = "Your Transaction No :-" + dtResult.Rows[0][0];
 
                pnlOrderPlacedSuccessfully.Visible = true;
 

              sendOrderPlacedAlert(txtCustomerName.Text, txtCustomerEmailID.Text, Convert.ToString(dtResult.Rows[0][0]));
 
              
 

                txtCustomerAddress.Text = string.Empty;
                txtCustomerEmailID.Text = string.Empty;
                txtCustomerName.Text = string.Empty;
                txtCustomerPhoneNo.Text = string.Empty;
                txtTotalPrice.Text = "0";
                txtTotalProducts.Text = "0";
            }


What I have tried:

IndexOutOfRange Exception was unhandled by user code There is no row at position 0, How to solve the error any one please guide to me.
Posted 11-Feb-16 19:55pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

There would be no rows in datatable dtResult
debug your code and check weather your function SaveCustomerDetails()
is adding record to your datatable or not.
  Permalink  
Comments
Boopalslm 12-Feb-16 2:21am
   
yes i am checking line by line my SaveCustomerDetails() table, but again same error is came.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Error is simple you have access a rows/column index which is not exist in dataset/datatable collection, in your code it looks you have used 'dtResult' variable, which is not defined anywhere in your code, I think you need to change your code as follows

CustomerID = Convert.ToInt32(dtResult.Rows[0][0])
//Insetad
CustomerID = Convert.ToInt32(dt.Rows[0][0])
  Permalink  
Comments
Boopalslm 12-Feb-16 2:24am
   
k working, but data's are not saved in SaveCustomerDetails() table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171017.2 | Last Updated 12 Feb 2016
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100