Click here to Skip to main content
14,690,505 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,

I just need hints. I created 3 tables from sql database explorer. The idea when the user selects items and add them to cart, then he orders them. When he orders them the data in AddToCart table deletes, but i want to retrieve them into order table. It works with gridview, by looping through it, but when i add another item to cart before ordering, it retrieves the data from the gridview interface of AddToCart Table, but deletes whole the data successfully from AddToCart Table including the extra data.

 foreach (GridViewRow g in GridView3.Rows)
            {
                TextBox myTextBox = (TextBox)(g.Cells[3].FindControl("TextBox1"));
                if (myTextBox.Text != " ")
                {
//string InsertData(int itemid, int itemcode, string itemname, int quantity)
                    InsertData(Convert.ToInt32(g.Cells[0].Text), Convert.ToInt32(g.Cells[1].Text), g.Cells[2].Text, Convert.ToInt32(myTextBox.Text));
                    str = str + g.Cells[0].Text + g.Cells[1].Text + g.Cells[2].Text + Convert.ToInt32(myTextBox.Text);
                }
            }


The given code works fine when they are data in the gridview interface, i need the records or data in the data table and insert them to "Order Table".

I tried as well as i could but the problem i did not understand well. I just want to apply to data table of order instead creating a data table. However, here i tried, but did not work.

try
            {

                
                SqlDataAdapter da = new SqlDataAdapter();
                
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                da.Fill(ds);


                //string str = " ";

                foreach (DataRow row in dt.Rows)
                {

                    string str = " ";
                    InsertData(Convert.ToInt32(row[0]), Convert.ToInt32(row[1]), row[2].ToString(), Convert.ToInt32(row[3]));

                    str = str + row[0] + row[1] + row[2] + row[3];

                    


                }
            }

            catch (Exception r)
            {
                Label3.Text = "Unsuccessful" + "Error" + r.Message;
            }


N.B: In the "string InsertData", i created sql connection and sql command for insert method with parameters and works fine with gridview.

Thanks,
Posted

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900