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. WPF
  4. Calculate the textbox value based on the value of combobox ? ( wpf )

Calculate the textbox value based on the value of combobox ? ( wpf )

Scheduled Pinned Locked Moved WPF
wpfcsharpdatabasehelpquestion
4 Posts 3 Posters 19 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.
  • M Offline
    M Offline
    Member_14680372
    wrote on last edited by
    #1

    I have a small program, because I'm new, my program is to bring data from sql sever to textbox via combobox option and use the value shown in that textbox to calculate the + I have made it to the step of putting up the data, now thanks to you to help me with the value calculation in the textbox, thank you for your help.

    xaml code :

    L Richard DeemingR 2 Replies Last reply
    0
    • M Member_14680372

      I have a small program, because I'm new, my program is to bring data from sql sever to textbox via combobox option and use the value shown in that textbox to calculate the + I have made it to the step of putting up the data, now thanks to you to help me with the value calculation in the textbox, thank you for your help.

      xaml code :

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What is the problem, and where does it occur?

      M 1 Reply Last reply
      0
      • L Lost User

        What is the problem, and where does it occur?

        M Offline
        M Offline
        Member_14680372
        wrote on last edited by
        #3

        https://www.upsieutoc.com/image/FSfuXK

        1 Reply Last reply
        0
        • M Member_14680372

          I have a small program, because I'm new, my program is to bring data from sql sever to textbox via combobox option and use the value shown in that textbox to calculate the + I have made it to the step of putting up the data, now thanks to you to help me with the value calculation in the textbox, thank you for your help.

          xaml code :

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

          Member 14680372 wrote:

          string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem + "';";

          Don't do it like that! Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^] How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^] Query Parameterization Cheat Sheet | OWASP[^]

          private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
          {
          using (SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial Catalog=LUAT;Integrated Security=True"))
          using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 * FROM comboboxnew WHERE code = @code;"))
          {
          cmd.Parameters.AddWithValue("@code", Convert.ToString(comboBox1.SelectedItem));

              con.Open();
              
              using (SqlDataReader myreader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
              {
                  if (myreader.Read())
                  {
                      string code = myreader.GetInt32(0).ToString();
                      string pieces = myreader.GetInt32(1).ToString();
                      string layers = myreader.GetInt32(2).ToString();
                      string productionpieces = myreader.GetInt32(3).ToString();
                      string seccond = myreader.GetInt32(4).ToString();
                      
                      txtcode.Text = code;
                      txtpieces.Text = pieces;
                      t
          

          "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