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. ask messagebox with sum record

ask messagebox with sum record

Scheduled Pinned Locked Moved C#
tutorial
6 Posts 4 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.
  • U Offline
    U Offline
    User 10240249
    wrote on last edited by
    #1

    how to create messagebox if save record success with sum record exemple string save=string.format("insert into quantity([input])values('{0}')",texbox1.tex); sqlconection con new sqlconection(); con.open(); sqlcommend cmd = new sqlcommend(); cmd.excutenonQuery(); con.close(); i want to show message=> messagebox.show"(Rcord 10 Item ");

    M 1 Reply Last reply
    0
    • U User 10240249

      how to create messagebox if save record success with sum record exemple string save=string.format("insert into quantity([input])values('{0}')",texbox1.tex); sqlconection con new sqlconection(); con.open(); sqlcommend cmd = new sqlcommend(); cmd.excutenonQuery(); con.close(); i want to show message=> messagebox.show"(Rcord 10 Item ");

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      1 Your insert query is wrong 2 You are using unverified data directly from your user - look up Little Bobby tables 3 You have no output from sql to get the information Personally I would build a parameterised stored procedure that insert/updates the record and returns the sum you are looking for. the result to be returned as either a single integer value using ExecuteScalar or as a table.

      Never underestimate the power of human stupidity RAH

      U 1 Reply Last reply
      0
      • M Mycroft Holmes

        1 Your insert query is wrong 2 You are using unverified data directly from your user - look up Little Bobby tables 3 You have no output from sql to get the information Personally I would build a parameterised stored procedure that insert/updates the record and returns the sum you are looking for. the result to be returned as either a single integer value using ExecuteScalar or as a table.

        Never underestimate the power of human stupidity RAH

        U Offline
        U Offline
        User 10240249
        wrote on last edited by
        #3

        i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");

        M S Richard DeemingR 3 Replies Last reply
        0
        • U User 10240249

          i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          You did not understand my last answer, you obviously have no idea how to do database operations and you are making the most basic error by storing dates as text. PLEASE get a book, work through the examples and then do some tutorials on the subject, you do not even have enough knowledge yet to as sensible questions.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • U User 10240249

            i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");

            S Offline
            S Offline
            Simon_Whale
            wrote on last edited by
            #5

            What Mycroft has stated is correct you shouldn't store dates in the database as strings but I wont go into that as he already has. If you look at the ExecuteNonQuery[^] documentation you will see that the method returns a value indicating the number of rows effected. you can then use this value in a string.

            string Message = String.Format("Number of rows affected {0}", result);
            MessageBox.Show(Message);

            Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

            1 Reply Last reply
            0
            • U User 10240249

              i want to show messagebox sum row/record with messagebox private void bsave_Click(object sender, EventArgs e) { string save = string.Format("Insert into ShippingCompany([ShippingCompanyCode],[ShippingCompanyName],[CurenccyCode],[ActiveStatus],[CreateBy],[CreateDate],[modifiedBy],[modifiedDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", t1.Text, t2.Text, t3.Text, t4.Text, t5.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss"), t7.Text, DateTime.Now.ToString("yyyy-mm-DD" + "HH:mm:ss")); SqlConnection con = new SqlConnection(dikonek); con.Open(); SqlCommand cmd = new SqlCommand(save, con); cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("?");

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Avoiding SQL Injection[^] isn't hard:

              string save = "Insert into ShippingCompany ([ShippingCompanyCode], [ShippingCompanyName], [CurenccyCode], [ActiveStatus], [CreateBy], [CreateDate], [modifiedBy], [modifiedDate]) "
              + "values (@ShippingCompanyCode, @ShippingCompanyName, @CurenccyCode, @ActiveStatus, @CreateBy, @CreateDate, @modifiedBy, @modifiedDate)";

              using (SqlConnection con = new SqlConnection(dikonek))
              using (SqlCommand cmd = new SqlCommand(save, con))
              {
              cmd.Parameters.AddWithValue("@ShippingCompanyCode", t1.Text);
              cmd.Parameters.AddWithValue("@ShippingCompanyName", t2.Text);
              cmd.Parameters.AddWithValue("@CurenccyCode", t3.Text);
              cmd.Parameters.AddWithValue("@ActiveStatus", t4.Text);
              cmd.Parameters.AddWithValue("@CreateBy", t5.Text);
              cmd.Parameters.AddWithValue("@CreateDate", DateTime.Now);
              cmd.Parameters.AddWithValue("@modifiedBy", t7.Text);
              cmd.Parameters.AddWithValue("@modifiedDate", DateTime.Now);

              con.Open();
              int rowsAffected = cmd.ExecuteNonQuery();
              MessageBox.Show(string.Format("{0} rows affected.", rowsAffected));
              }

              You should also consider giving your controls more meaningful names than t1, t2, etc.


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              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