update problem
-
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);
-
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);
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!
-
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!
-
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!
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(); }
-
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(); }
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!
-
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!