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. problem to make a second recording

problem to make a second recording

Scheduled Pinned Locked Moved C#
helpdatabasetutorialquestion
13 Posts 3 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 ago2486

    the goal is to add and save later I can do it once when I want to do it for a second time I have an error: unable to find table 0, I must close the form and open it again so that I can do another one ... how to solve this problem without closing my form before?

    private void BtnAjouter_Click(object sender, EventArgs e)
    {
    int total;
    decimal total_achat;
    //si les champs sont vides
    if (TxtDesignation.Text == "" || TxtPrixUnitaire.Text == "" || TxtQteCmd.Text == "" || TxtQteStock.Text == "" || TxtRefProduit.Text == "")
    {
    MessageBox.Show("Rassurez vous que tous les champs ont bien été rempli.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
    //Vérifier si la valeur saisie est numeric
    if (Int32.TryParse(TxtQteCmd.Text, out int value) && TxtRefProduit.Text != "")
    {
    //Vérifier si la commande est inferieur ou egale au stock
    int a = 0;
    int b = 0;
    int c;

                    //Convertire les textBox en int
                    int.TryParse(TxtQteCmd.Text.Trim(), out a);
                    int.TryParse(TxtQteStock.Text.Trim(), out b);
                    int.TryParse(TxtPrixUnitaire.Text.Trim(), out c);
    
                    if (a <= b)
                    {
                        total = a \* c;
                        total\_achat = 0;
    
                        try
                        {
            
                            setConnection();
                            sql\_con.Open();
                            using (OleDbCommand cmd = sql\_con.CreateCommand())
                            {
                                cmd.CommandText = "INSERT INTO Detail\_temp (ref\_det, qute\_det, Designation, Prix\_unitaire\_HT, Prix\_total\_HT) VALUES (@ref\_det,@qute\_det,@Designation,@Prix\_unitaire\_HT,@Prix\_total\_HT)";
                                cmd.Parameters.AddWithValue("@ref\_det", TxtRefProduit.Text);
                                cmd.Parameters.AddWithValue("@qute\_det", TxtQteCmd.Text);
                                cmd.Parameters.AddWithValue("@Designation", TxtDesignation.Text);
                                cmd.Parameters.AddWithValue("@Prix\_unitaire\_HT", TxtPrixUnitaire.Text);
                                cmd.Parameters.AddWithValue("@Prix\_total\_HT", total);
    
    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    Just what does DB have to do with anything?

    DB.Fill(DS);

    It doesn't have any obvious relation to the Connection object, or to the Command - so why would you expect it to do anything useful? Come on man, you need to start thinking here - instead of just copy'n'paste code from somewhere else and hoping it works!

    "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

      Just what does DB have to do with anything?

      DB.Fill(DS);

      It doesn't have any obvious relation to the Connection object, or to the Command - so why would you expect it to do anything useful? Come on man, you need to start thinking here - instead of just copy'n'paste code from somewhere else and hoping it works!

      "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

      you may be right but i have declared its objects to display the info in the datagridview
        private OleDbDataAdapter DB;
        private DataSet DS = new DataSet ();
        private DataTable DT = new DataTable ();
      thanks for guiding me

      OriginalGriffO 1 Reply Last reply
      0
      • A ago2486

        you may be right but i have declared its objects to display the info in the datagridview
          private OleDbDataAdapter DB;
          private DataSet DS = new DataSet ();
          private DataTable DT = new DataTable ();
        thanks for guiding me

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #4

        Oh gawd, I only stopped banging my head on the desk yesterday ... Stop and think. Where are you getting the data from? How does the data source connect to the DataSet? How does the DataSet connect to the DataTable? How does the DataTable connect to the DataGridView? Any one of those links is wrong ... and you don't get data ... Seriously man - get a book and start reading. You aren't helping yourself by trying and hoping - all you do is make yourself look ... umm ... pretty silly, he said as politely as he could manage. :laugh:

        "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

          Oh gawd, I only stopped banging my head on the desk yesterday ... Stop and think. Where are you getting the data from? How does the data source connect to the DataSet? How does the DataSet connect to the DataTable? How does the DataTable connect to the DataGridView? Any one of those links is wrong ... and you don't get data ... Seriously man - get a book and start reading. You aren't helping yourself by trying and hoping - all you do is make yourself look ... umm ... pretty silly, he said as politely as he could manage. :laugh:

          "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
          #5

          thank you sir i will read and get back to you because i feel like an idiot. I will review her and let you know.

          OriginalGriffO 1 Reply Last reply
          0
          • A ago2486

            thank you sir i will read and get back to you because i feel like an idiot. I will review her and let you know.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #6

            Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:

            "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

              Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:

              "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
              #7

              thank you sir because you give me courage I will review some court about it to find a solution I will come back to you even if I do not manage

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                Don't feel like an idiot, just learn the basics - because until you understand what you are doing, you are just whistling in the dark and hoping the noise attracts solutions rather than monsters ... :laugh:

                "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
                #8

                sir you are right these lines were useless, they were useless ...
                I just saw its The DataAdapter object serves as a link between a DataSet object and a data source.
                  A .NET data provider will use a DataAdapter object to fill data with a DataSet and then pass on the changes made to a data source.

                OriginalGriffO 1 Reply Last reply
                0
                • A ago2486

                  sir you are right these lines were useless, they were useless ...
                  I just saw its The DataAdapter object serves as a link between a DataSet object and a data source.
                    A .NET data provider will use a DataAdapter object to fill data with a DataSet and then pass on the changes made to a data source.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #9

                  Yes it does - but that doesn't mean that you create an instance and "magic happens" :laugh:

                  "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

                    Yes it does - but that doesn't mean that you create an instance and "magic happens" :laugh:

                    "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
                    #10

                    yes sir i already did to change the datagridview

                    private void LoadDB()
                    {
                    setConnection();
                    sql_con.Open();
                    sql_cmd = sql_con.CreateCommand();
                    string CommandText = "SELECT * FROM Detail_temp";
                    DB = new OleDbDataAdapter(CommandText, sql_con);
                    DS.Reset();
                    DB.Fill(DS);
                    DT = DS.Tables[0];
                    dataGridView1.DataSource = DT;
                    sql_con.Close();
                    }

                    maybe I'm wrong? but I did it to see my recordings in the datagridview

                    OriginalGriffO 1 Reply Last reply
                    0
                    • A ago2486

                      yes sir i already did to change the datagridview

                      private void LoadDB()
                      {
                      setConnection();
                      sql_con.Open();
                      sql_cmd = sql_con.CreateCommand();
                      string CommandText = "SELECT * FROM Detail_temp";
                      DB = new OleDbDataAdapter(CommandText, sql_con);
                      DS.Reset();
                      DB.Fill(DS);
                      DT = DS.Tables[0];
                      dataGridView1.DataSource = DT;
                      sql_con.Close();
                      }

                      maybe I'm wrong? but I did it to see my recordings in the datagridview

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #11

                      That's better - but in the code you showed to start with, you didn't do that, did you?

                      "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

                        That's better - but in the code you showed to start with, you didn't do that, did you?

                        "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
                        #12

                        yes sir and again thank you for your advice

                        Z 1 Reply Last reply
                        0
                        • A ago2486

                          yes sir and again thank you for your advice

                          Z Offline
                          Z Offline
                          ZurdoDev
                          wrote on last edited by
                          #13

                          Off topic, but why do you keep putting your messages in text tags?

                          Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                          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