Click here to Skip to main content
14,550,379 members
   

C#

 
GeneralRe: problem to make a second recording Pin
OriginalGriff19-Mar-20 2:26
mveOriginalGriff19-Mar-20 2:26 
GeneralRe: problem to make a second recording Pin
ago248619-Mar-20 3:04
Memberago248619-Mar-20 3:04 
GeneralRe: problem to make a second recording Pin
OriginalGriff19-Mar-20 3:22
mveOriginalGriff19-Mar-20 3:22 
GeneralRe: problem to make a second recording Pin
ago248619-Mar-20 3:27
Memberago248619-Mar-20 3:27 
QuestionRe: problem to make a second recording Pin
ZurdoDev19-Mar-20 3:51
mveZurdoDev19-Mar-20 3:51 
QuestionHow to solve 100 Doors Kata using TDD in C# Pin
User-862169518-Mar-20 5:30
MemberUser-862169518-Mar-20 5:30 
AnswerRe: How to solve 100 Doors Kata using TDD in C# Pin
Bohdan Stupak19-Mar-20 5:12
professionalBohdan Stupak19-Mar-20 5:12 
Questionproblem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 3:13
Memberago248618-Mar-20 3:13 
good evening gentlemen and thank you to you who brought me help but I am continuing my project and I have a problem retrieving info from one table to insert it into another.
I have three tables which are related
1.product (article_ID, design, price_U, Qty)
2.order (com_number, com_date, com_amount)
3.detail_command (num_det, num_com, ID_article, qute_det)
I can't fill the detail_commende table. It must be said that I am lost. can you put me on the track please
I may have made a serious mistake in my codes.



private void BtnValider_Click(object sender, EventArgs e)
      {
          DialogResult dialogResult = MessageBox.Show("Voulez vous valider la facture?", "VALIDATION DE LA FACTURE", MessageBoxButtons.YesNo);
          if (dialogResult == DialogResult.Yes)
          {
              try
              {

                  setConnection();
                  sql_con.Open();

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

                      cmd1.CommandText = "INSERT INTO Commandes (montant_com) VALUES (@montant_com)";
                      cmd1.Parameters.AddWithValue("@montant_com", TxtTotalCmd.Text);
                      //sql_cmd = new OleDbCommand(CommandText, sql_con);
                      cmd1.ExecuteNonQuery();
                      //ADODB.Recordset dbrst = new ADODB.Recordset();
                  }

                  long Qte_prod, numCmd;
                  string ref_prod;


                  using (OleDbCommand cmd2 = sql_con.CreateCommand())
                  {
                      //setConnection();

                      cmd2.CommandText = "SELECT MAX(num_com) AS dernier_num FROM Commandes";
                      // cmd2.Connection.Open();
                     // sql_con.Open();
                      object result = cmd2.ExecuteScalar();
                      if (result is null || Convert.IsDBNull(result))
                      {
                          numCmd = 0;
                      }
                      else
                      {
                          numCmd = Convert.ToInt64(result);
                          TxtNunCmd.Text = numCmd.ToString();


                          //LoadDB();
                          //object result1 = cmd3.ExecuteScalar();
                          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);
                                      cmd3.ExecuteNonQuery(); //***I have an error at this level: INSERT INTO syntax error

                                  }

                                  using (OleDbCommand cmd4 = sql_con.CreateCommand())
                                  {
                                      setConnection();
                                      cmd4.CommandText = "UPDATE Catalogue SET Quantite = Quantite - (@Qte_cmd) WHERE code_article = (@code_article)";
                                      cmd4.Parameters.AddWithValue("@Qte_cmd", Qte_prod);
                                      cmd4.Parameters.AddWithValue("@code_article", TxtRefProduit.Text);
                                      cmd4.ExecuteNonQuery();

                                  }
                              }
                          sql_con.Close();
                          SupDetail_Temp();
                          //vider();
                          TxtTotalCmd.Text = "";



                      }
                  }

              }

              catch (Exception ex)
              {
                  MessageBox.Show(ex.ToString());
                  sql_con.Close();
              }
          }
          else if (dialogResult == DialogResult.No)
          {
              //do something else
          }

      }

AnswerRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 3:50
mveOriginalGriff18-Mar-20 3:50 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 4:11
Memberago248618-Mar-20 4:11 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 4:17
mveOriginalGriff18-Mar-20 4:17 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 4:24
Memberago248618-Mar-20 4:24 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 5:01
mveOriginalGriff18-Mar-20 5:01 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 5:12
Memberago248618-Mar-20 5:12 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 5:13
mveOriginalGriff18-Mar-20 5:13 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 5:16
mveOriginalGriff18-Mar-20 5:16 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 5:30
Memberago248618-Mar-20 5:30 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 5:33
Memberago248618-Mar-20 5:33 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 5:39
mveOriginalGriff18-Mar-20 5:39 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 5:42
Memberago248618-Mar-20 5:42 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 5:52
mveOriginalGriff18-Mar-20 5:52 
GeneralRe: problem retrieving info from one table to insert it into another Pin
ago248618-Mar-20 5:56
Memberago248618-Mar-20 5:56 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 6:01
mveOriginalGriff18-Mar-20 6:01 
GeneralRe: problem retrieving info from one table to insert it into another Pin
Luc Pattyn18-Mar-20 6:04
sitebuilderLuc Pattyn18-Mar-20 6:04 
GeneralRe: problem retrieving info from one table to insert it into another Pin
OriginalGriff18-Mar-20 6:11
mveOriginalGriff18-Mar-20 6:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.