Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

I have some issues in datagridview

$
0
0

Hello, i have some problems and i hope somebody can help me please.

when i insert a new product with the same Id, i need the price just to be refreshed not add a new row, and if it is not i need a new row

DaL.Open();
                SqlCommand cmd = new SqlCommand("Select*from Produit where produit_Id='" + productsBox.SelectedValue.ToString() + "'", DAL.Acesslayer.Conx);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (PanelGrid.Rows.Count == 0)
                    {
                        Quantity_Price = int.Parse(quantityBox.Value.ToString()) * int.Parse(dt.Rows[i][3].ToString());
                        PanelGrid.Rows.Add(dt.Rows[i][0], dt.Rows[i][1], quantityBox.Value.ToString(), Quantity_Price.ToString(), dt.Rows[i][5]);
                    }

                        Found = FC.SearchProduct(PanelGrid.Rows[i].Cells[1].Value.ToString());
                        MessageBox.Show(PanelGrid.Rows[i].Cells[1].Value.ToString());
                        if (Found == true)
                        {

                            PanelGrid.Rows.RemoveAt(i);
                            Quantity_Price = int.Parse(quantityBox.Value.ToString()) * int.Parse(dt.Rows[i][3].ToString());
                            PanelGrid.Rows.Add(dt.Rows[i][0], dt.Rows[i][1], quantityBox.Value.ToString(), Quantity_Price.ToString(), dt.Rows[i][5]);

                        }
                        else
                        {
                            if (Found ==false && PanelGrid.Rows.Count != 0)
                            {
                                Quantity_Price = int.Parse(quantityBox.Value.ToString()) * int.Parse(dt.Rows[i][3].ToString());
                                PanelGrid.Rows.Add(dt.Rows[i][0], dt.Rows[i][1], quantityBox.Value.ToString(), Quantity_Price.ToString(), dt.Rows[i][5]);

                            }
                        }

                }

                                      

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>