Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C ASP.NET
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 2-Apr-13 3:20am

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 295
1 OriginalGriff 274
2 Shweta N Mishra 216
3 PIEBALDconsult 184
4 CPallini 155
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
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