How can I know how many lines were last inserted by Datagridview into Oracle











up vote
0
down vote

favorite












I'm programming an application that DataGridView should insert into Oracle after clicking a button. How can I know how many lines were last inserted into Oracle. At best a message should appear. Thanks



private void button4_Click(object sender, EventArgs e)
{

try
{

for (int i = 0; i < dataGridViewDoubleBuffered1.Rows.Count - 1; i++) //Schleife für INSERT Befehl
{

OracleConnection con = new OracleConnection(XXXXXXX);
con.Open();

string sql = "INSERT INTO AFTERSALES.INPUT_BOARDLEVEL_REPAIR_LDS (BLR_REPORT_DATE, MONTH_OF_REPAIR_END, PCB_COUNTER) "
+ "VALUES (:BLR_REPORT_DATE, :MONTH_OF_REPAIR_END, :PCB_COUNTER)";

OracleCommand cmd = new OracleCommand(sql, con);
cmd.CommandText = sql;
cmd.Parameters.Add(":BLR_REPORT_DATE", Convert.ToString(dataGridViewDoubleBuffered1.Rows[i].Cells[0].Value));
cmd.Parameters.Add(":MONTH_OF_REPAIR_END", dataGridViewDoubleBuffered1.Rows[i].Cells[1].Value);
cmd.Parameters.Add(":PCB_COUNTER", dataGridViewDoubleBuffered1.Rows[i].Cells[2].Value);
cmd.ExecuteNonQuery();
con.Close();
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}

}









share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm programming an application that DataGridView should insert into Oracle after clicking a button. How can I know how many lines were last inserted into Oracle. At best a message should appear. Thanks



    private void button4_Click(object sender, EventArgs e)
    {

    try
    {

    for (int i = 0; i < dataGridViewDoubleBuffered1.Rows.Count - 1; i++) //Schleife für INSERT Befehl
    {

    OracleConnection con = new OracleConnection(XXXXXXX);
    con.Open();

    string sql = "INSERT INTO AFTERSALES.INPUT_BOARDLEVEL_REPAIR_LDS (BLR_REPORT_DATE, MONTH_OF_REPAIR_END, PCB_COUNTER) "
    + "VALUES (:BLR_REPORT_DATE, :MONTH_OF_REPAIR_END, :PCB_COUNTER)";

    OracleCommand cmd = new OracleCommand(sql, con);
    cmd.CommandText = sql;
    cmd.Parameters.Add(":BLR_REPORT_DATE", Convert.ToString(dataGridViewDoubleBuffered1.Rows[i].Cells[0].Value));
    cmd.Parameters.Add(":MONTH_OF_REPAIR_END", dataGridViewDoubleBuffered1.Rows[i].Cells[1].Value);
    cmd.Parameters.Add(":PCB_COUNTER", dataGridViewDoubleBuffered1.Rows[i].Cells[2].Value);
    cmd.ExecuteNonQuery();
    con.Close();
    }

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }

    }









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm programming an application that DataGridView should insert into Oracle after clicking a button. How can I know how many lines were last inserted into Oracle. At best a message should appear. Thanks



      private void button4_Click(object sender, EventArgs e)
      {

      try
      {

      for (int i = 0; i < dataGridViewDoubleBuffered1.Rows.Count - 1; i++) //Schleife für INSERT Befehl
      {

      OracleConnection con = new OracleConnection(XXXXXXX);
      con.Open();

      string sql = "INSERT INTO AFTERSALES.INPUT_BOARDLEVEL_REPAIR_LDS (BLR_REPORT_DATE, MONTH_OF_REPAIR_END, PCB_COUNTER) "
      + "VALUES (:BLR_REPORT_DATE, :MONTH_OF_REPAIR_END, :PCB_COUNTER)";

      OracleCommand cmd = new OracleCommand(sql, con);
      cmd.CommandText = sql;
      cmd.Parameters.Add(":BLR_REPORT_DATE", Convert.ToString(dataGridViewDoubleBuffered1.Rows[i].Cells[0].Value));
      cmd.Parameters.Add(":MONTH_OF_REPAIR_END", dataGridViewDoubleBuffered1.Rows[i].Cells[1].Value);
      cmd.Parameters.Add(":PCB_COUNTER", dataGridViewDoubleBuffered1.Rows[i].Cells[2].Value);
      cmd.ExecuteNonQuery();
      con.Close();
      }

      }
      catch (Exception ex)
      {
      MessageBox.Show(ex.ToString());
      }

      }









      share|improve this question













      I'm programming an application that DataGridView should insert into Oracle after clicking a button. How can I know how many lines were last inserted into Oracle. At best a message should appear. Thanks



      private void button4_Click(object sender, EventArgs e)
      {

      try
      {

      for (int i = 0; i < dataGridViewDoubleBuffered1.Rows.Count - 1; i++) //Schleife für INSERT Befehl
      {

      OracleConnection con = new OracleConnection(XXXXXXX);
      con.Open();

      string sql = "INSERT INTO AFTERSALES.INPUT_BOARDLEVEL_REPAIR_LDS (BLR_REPORT_DATE, MONTH_OF_REPAIR_END, PCB_COUNTER) "
      + "VALUES (:BLR_REPORT_DATE, :MONTH_OF_REPAIR_END, :PCB_COUNTER)";

      OracleCommand cmd = new OracleCommand(sql, con);
      cmd.CommandText = sql;
      cmd.Parameters.Add(":BLR_REPORT_DATE", Convert.ToString(dataGridViewDoubleBuffered1.Rows[i].Cells[0].Value));
      cmd.Parameters.Add(":MONTH_OF_REPAIR_END", dataGridViewDoubleBuffered1.Rows[i].Cells[1].Value);
      cmd.Parameters.Add(":PCB_COUNTER", dataGridViewDoubleBuffered1.Rows[i].Cells[2].Value);
      cmd.ExecuteNonQuery();
      con.Close();
      }

      }
      catch (Exception ex)
      {
      MessageBox.Show(ex.ToString());
      }

      }






      c# winforms datagridview oracle11g






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 13:21









      Yves

      425




      425
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          ExecuteNonQuery returns number of rows affected.



          So,



          var numRowsInserted = cmd.ExecuteNonQuery();





          share|improve this answer





















          • Thank you very much. Can you give me please a sample.
            – Yves
            Nov 7 at 13:29










          • @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
            – dcp
            Nov 7 at 13:32




















          up vote
          0
          down vote













          int recordsAffected = cmd.ExecuteNonQuery();


          From https://docs.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oraclecommand.executenonquery?view=netframework-4.7.2:




          Returns Int32 For UPDATE, INSERT, and DELETE statements, the return
          value is the number of rows affected by the command.







          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190328%2fhow-can-i-know-how-many-lines-were-last-inserted-by-datagridview-into-oracle%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            ExecuteNonQuery returns number of rows affected.



            So,



            var numRowsInserted = cmd.ExecuteNonQuery();





            share|improve this answer





















            • Thank you very much. Can you give me please a sample.
              – Yves
              Nov 7 at 13:29










            • @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
              – dcp
              Nov 7 at 13:32

















            up vote
            0
            down vote













            ExecuteNonQuery returns number of rows affected.



            So,



            var numRowsInserted = cmd.ExecuteNonQuery();





            share|improve this answer





















            • Thank you very much. Can you give me please a sample.
              – Yves
              Nov 7 at 13:29










            • @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
              – dcp
              Nov 7 at 13:32















            up vote
            0
            down vote










            up vote
            0
            down vote









            ExecuteNonQuery returns number of rows affected.



            So,



            var numRowsInserted = cmd.ExecuteNonQuery();





            share|improve this answer












            ExecuteNonQuery returns number of rows affected.



            So,



            var numRowsInserted = cmd.ExecuteNonQuery();






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 7 at 13:27









            dcp

            42.3k16118144




            42.3k16118144












            • Thank you very much. Can you give me please a sample.
              – Yves
              Nov 7 at 13:29










            • @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
              – dcp
              Nov 7 at 13:32




















            • Thank you very much. Can you give me please a sample.
              – Yves
              Nov 7 at 13:29










            • @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
              – dcp
              Nov 7 at 13:32


















            Thank you very much. Can you give me please a sample.
            – Yves
            Nov 7 at 13:29




            Thank you very much. Can you give me please a sample.
            – Yves
            Nov 7 at 13:29












            @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
            – dcp
            Nov 7 at 13:32






            @Yves - I provided a code sample already. If anything's not clear, feel free to ask. Note that since you are in a loop, you may need to add to the variable (e.g. numRowsInserted += cmd.ExecuteNonQuery()).
            – dcp
            Nov 7 at 13:32














            up vote
            0
            down vote













            int recordsAffected = cmd.ExecuteNonQuery();


            From https://docs.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oraclecommand.executenonquery?view=netframework-4.7.2:




            Returns Int32 For UPDATE, INSERT, and DELETE statements, the return
            value is the number of rows affected by the command.







            share|improve this answer

























              up vote
              0
              down vote













              int recordsAffected = cmd.ExecuteNonQuery();


              From https://docs.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oraclecommand.executenonquery?view=netframework-4.7.2:




              Returns Int32 For UPDATE, INSERT, and DELETE statements, the return
              value is the number of rows affected by the command.







              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                int recordsAffected = cmd.ExecuteNonQuery();


                From https://docs.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oraclecommand.executenonquery?view=netframework-4.7.2:




                Returns Int32 For UPDATE, INSERT, and DELETE statements, the return
                value is the number of rows affected by the command.







                share|improve this answer












                int recordsAffected = cmd.ExecuteNonQuery();


                From https://docs.microsoft.com/en-us/dotnet/api/system.data.oracleclient.oraclecommand.executenonquery?view=netframework-4.7.2:




                Returns Int32 For UPDATE, INSERT, and DELETE statements, the return
                value is the number of rows affected by the command.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 7 at 13:27









                Miamy

                604413




                604413






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53190328%2fhow-can-i-know-how-many-lines-were-last-inserted-by-datagridview-into-oracle%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini