|  |  | 
            
              | ผม ทำไว้อย่างนี้ พอเลือก 2อัน มัน insert แค่ อันเดียว คืออันสุดท้าย อะครับ 
 Code (C#)
 
  protected void btnCon_Click(object sender, ImageClickEventArgs e)
        {
            ArrayList al = new ArrayList();
            bool selectRow;
            
            foreach(GridViewRow gvr in GridView1.Rows)
            {
                selectRow = ((CheckBox)(gvr.FindControl("CheckBox1"))).Checked;
                
                    if (selectRow == true)
                    {
                        string Username = ((Label)(gvr.FindControl("lblUsername"))).Text;
                        string ProductName = ((Label)(gvr.FindControl("lblProductName"))).Text;
                        string Qty = ((Label)(gvr.FindControl("lblQty"))).Text;
                        Int32 Qtysum = Convert.ToInt32(Qty);
                        string TotalPrice = ((Label)(gvr.FindControl("lblTotalPrice"))).Text;
                        Int32 Price = Convert.ToInt32(TotalPrice);
                        string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                        SqlConnection conn = new SqlConnection(strconn);
                        conn.Open();
                        string commandtext = @"INSERT INTO confirm(Username,ProductName,ConfirmDate,Qty,TotalPrice) VALUES (@Username , @ProductName , @ConfirmDate , @Qty , @TotalPrice)";
                        SqlCommand com = new SqlCommand(commandtext, conn);
                        com.Parameters.Add("@Username", SqlDbType.NVarChar).Value = Username;
                        com.Parameters.Add("@ProductName", SqlDbType.NVarChar).Value = ProductName;
                        com.Parameters.Add("@ConfirmDate", SqlDbType.DateTime).Value = DateTime.Now;
                        com.Parameters.Add("@Qty", SqlDbType.Int).Value = Qtysum;
                        com.Parameters.Add("@TotalPrice", SqlDbType.Int).Value = Price;
                        if (conn.State == ConnectionState.Open)
                        { conn.Close(); }
                        conn.Open();
                        com.ExecuteNonQuery();
                        conn.Close();
                        Response.Redirect("index.aspx");
                    }
                
            }
 |  
              | 
 ประวัติการแก้ไข
 2012-09-05 16:37:03
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-09-05 16:36:34 | By :
                            thewinner55 |  |  |  
                  |  |  |  |  |  |  |