Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. update problem

update problem

Scheduled Pinned Locked Moved C#
helpdatabasecomannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ago2486
    wrote on last edited by
    #1

    Quote:

    hello gentlemen and thank you to you who bring me your help. I am almost at the end of my program and I have an update problem. I don't see any change in my stock. I have no error when I validate but the quantity does not change in the access database

    for (int i = 0; i < dataGridView1.Rows.Count; i++) //Car tu fais une infériorité stricte
    {
    ref_prod = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
    Qte_prod = Convert.ToInt64(dataGridView1.Rows[i].Cells[1].Value);

                                    using (OleDbCommand cmd3 = sql\_con.CreateCommand())
                                    {
                                        
                                        cmd3.CommandText = "INSERT INTO Detail\_commandes (com\_det, ref\_det, qute\_det) VALUES (@com\_det,@ref\_det,@qute\_det)";
                                        cmd3.Parameters.AddWithValue("@com\_det", TxtNunCmd.Text);
                                        cmd3.Parameters.AddWithValue("@ref\_det", ref\_prod);
                                        cmd3.Parameters.AddWithValue("@qute\_det", Qte\_prod);
                                        sql\_con.Open();
                                        cmd3.ExecuteNonQuery();
                                        sql\_con.Close();
    
                                    }
    
                                    using (OleDbCommand cmd4 = sql\_con.CreateCommand())
                                    {
                                        //setConnection();
                                        OleDbCommand QteStock = sql\_con.CreateCommand();
                                        QteStock.CommandText = "SELECT Quantite FROM Catalogue";
                                        sql\_con.Open();
                                        int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
                                        sql\_con.Close();
                                        cmd4.CommandText = "UPDATE Catalogue SET Quantite = @Quantite - @QteStc WHERE code\_article = (@code\_article)";
                                        cmd4.Parameters.AddWithValue("@Quantite", LastQteStock);
                                        cmd4.Parameters.AddWithValue("@QteStc", Qte\_prod);
                                        cmd4.Parameters.AddWithValue("@code\_article", TxtRefProduit.Text);
    
    OriginalGriffO 1 Reply Last reply
    0
    • A ago2486

      Quote:

      hello gentlemen and thank you to you who bring me your help. I am almost at the end of my program and I have an update problem. I don't see any change in my stock. I have no error when I validate but the quantity does not change in the access database

      for (int i = 0; i < dataGridView1.Rows.Count; i++) //Car tu fais une infériorité stricte
      {
      ref_prod = Convert.ToString(dataGridView1.Rows[i].Cells[0].Value);
      Qte_prod = Convert.ToInt64(dataGridView1.Rows[i].Cells[1].Value);

                                      using (OleDbCommand cmd3 = sql\_con.CreateCommand())
                                      {
                                          
                                          cmd3.CommandText = "INSERT INTO Detail\_commandes (com\_det, ref\_det, qute\_det) VALUES (@com\_det,@ref\_det,@qute\_det)";
                                          cmd3.Parameters.AddWithValue("@com\_det", TxtNunCmd.Text);
                                          cmd3.Parameters.AddWithValue("@ref\_det", ref\_prod);
                                          cmd3.Parameters.AddWithValue("@qute\_det", Qte\_prod);
                                          sql\_con.Open();
                                          cmd3.ExecuteNonQuery();
                                          sql\_con.Close();
      
                                      }
      
                                      using (OleDbCommand cmd4 = sql\_con.CreateCommand())
                                      {
                                          //setConnection();
                                          OleDbCommand QteStock = sql\_con.CreateCommand();
                                          QteStock.CommandText = "SELECT Quantite FROM Catalogue";
                                          sql\_con.Open();
                                          int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
                                          sql\_con.Close();
                                          cmd4.CommandText = "UPDATE Catalogue SET Quantite = @Quantite - @QteStc WHERE code\_article = (@code\_article)";
                                          cmd4.Parameters.AddWithValue("@Quantite", LastQteStock);
                                          cmd4.Parameters.AddWithValue("@QteStc", Qte\_prod);
                                          cmd4.Parameters.AddWithValue("@code\_article", TxtRefProduit.Text);
      
      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Once again: use the debugger. Find out what the numbers are, find out what the code-article value is. Then before you call ExecuteNonQuery to perform the update, check your DB for the exact current values using an Access query to find the specific rows. Work out what the new row values should be for the numbers you looked at. Step over the ExecuteNonQuery, and look at the same set of rows. Are they the new values? We can't do any of that for you, we don't have your DB.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      A 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        Once again: use the debugger. Find out what the numbers are, find out what the code-article value is. Then before you call ExecuteNonQuery to perform the update, check your DB for the exact current values using an Access query to find the specific rows. Work out what the new row values should be for the numbers you looked at. Step over the ExecuteNonQuery, and look at the same set of rows. Are they the new values? We can't do any of that for you, we don't have your DB.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

        A Offline
        A Offline
        ago2486
        wrote on last edited by
        #3

        Understood sir and thank you for your promptness. i will keep looking

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Once again: use the debugger. Find out what the numbers are, find out what the code-article value is. Then before you call ExecuteNonQuery to perform the update, check your DB for the exact current values using an Access query to find the specific rows. Work out what the new row values should be for the numbers you looked at. Step over the ExecuteNonQuery, and look at the same set of rows. Are they the new values? We can't do any of that for you, we don't have your DB.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

          A Offline
          A Offline
          ago2486
          wrote on last edited by
          #4

          Sir I am happy because I was able to find a solution, its not easy because I really did not know how to go about it to see what is wrong. but I was able to post my request in a texbox to see what was wrong. I do not know my code is clean but the update is done.
          How to find the code?

          using (OleDbCommand cmd4 = sql_con.CreateCommand())
          {

                                              //setConnection();
                                              OleDbCommand QteStock = sql\_con.CreateCommand();
                                              QteStock.CommandText = "SELECT Quantite FROM Catalogue";
                                              sql\_con.Open();
                                              int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
                                              sql\_con.Close();
                                              string query = "UPDATE Catalogue SET Quantite = (@quantite - @QteStc) WHERE Code\_article = (@code\_article)";
                                              cmd4.CommandText = query;
                                              MessageBox.Show(query);
                                              cmd4.Parameters.AddWithValue("@quantite", LastQteStock);
                                              cmd4.Parameters.AddWithValue("@QteStc", Qte\_prod);
                                              cmd4.Parameters.AddWithValue("@code\_article", ref\_prod);
                                              sql\_con.Open();
                                              cmd4.ExecuteNonQuery();
                                              sql\_con.Close();
          
                                          }
          
          OriginalGriffO 1 Reply Last reply
          0
          • A ago2486

            Sir I am happy because I was able to find a solution, its not easy because I really did not know how to go about it to see what is wrong. but I was able to post my request in a texbox to see what was wrong. I do not know my code is clean but the update is done.
            How to find the code?

            using (OleDbCommand cmd4 = sql_con.CreateCommand())
            {

                                                //setConnection();
                                                OleDbCommand QteStock = sql\_con.CreateCommand();
                                                QteStock.CommandText = "SELECT Quantite FROM Catalogue";
                                                sql\_con.Open();
                                                int LastQteStock = Convert.ToInt32(QteStock.ExecuteScalar());
                                                sql\_con.Close();
                                                string query = "UPDATE Catalogue SET Quantite = (@quantite - @QteStc) WHERE Code\_article = (@code\_article)";
                                                cmd4.CommandText = query;
                                                MessageBox.Show(query);
                                                cmd4.Parameters.AddWithValue("@quantite", LastQteStock);
                                                cmd4.Parameters.AddWithValue("@QteStc", Qte\_prod);
                                                cmd4.Parameters.AddWithValue("@code\_article", ref\_prod);
                                                sql\_con.Open();
                                                cmd4.ExecuteNonQuery();
                                                sql\_con.Close();
            
                                            }
            
            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            Seriously, learn to use the debugger - it will show you exactly what is happening while your code is running. It lets you look at variables to check what they contain - and compare them to what you think they should contain - execute your code line by line, and a load of other things. It's your biggest friend in development - and the place you should be spending most of your time!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            A 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Seriously, learn to use the debugger - it will show you exactly what is happening while your code is running. It lets you look at variables to check what they contain - and compare them to what you think they should contain - execute your code line by line, and a load of other things. It's your biggest friend in development - and the place you should be spending most of your time!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

              A Offline
              A Offline
              ago2486
              wrote on last edited by
              #6

              Understood sir and thank you for your frankness. I will continue following your advice

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups