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. Web Development
  3. ASP.NET
  4. TextBox.text as parameter in query

TextBox.text as parameter in query

Scheduled Pinned Locked Moved ASP.NET
databasequestionannouncement
5 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.
  • K Offline
    K Offline
    kallileo
    wrote on last edited by
    #1

    How can I pass the value from texbox.text as parameter in my SQL query? Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim txt As Integer Dim updateCMD As SqlCommand Dim query As String txt = TextBox1.Text query = "UPDATE [Temp] SET [value] = '??????' WHERE [name] = 'temprature'" updateCMD = New SqlCommand(query, SQLconn) updateCMD.CommandType = CommandType.Text SQLconn.Open() updateCMD.ExecuteNonQuery() SQLconn.Close() End Sub Thanks

    S M 2 Replies Last reply
    0
    • K kallileo

      How can I pass the value from texbox.text as parameter in my SQL query? Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim txt As Integer Dim updateCMD As SqlCommand Dim query As String txt = TextBox1.Text query = "UPDATE [Temp] SET [value] = '??????' WHERE [name] = 'temprature'" updateCMD = New SqlCommand(query, SQLconn) updateCMD.CommandType = CommandType.Text SQLconn.Open() updateCMD.ExecuteNonQuery() SQLconn.Close() End Sub Thanks

      S Offline
      S Offline
      szukuro
      wrote on last edited by
      #2

      Modify query like this: query = "UPDATE [Temp] SET [value] = @text WHERE [name] = 'temprature'" Add this: updateCMD.Parameters.AddWithValue("@text", Textbox1.Text);

      1 Reply Last reply
      0
      • K kallileo

        How can I pass the value from texbox.text as parameter in my SQL query? Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim txt As Integer Dim updateCMD As SqlCommand Dim query As String txt = TextBox1.Text query = "UPDATE [Temp] SET [value] = '??????' WHERE [name] = 'temprature'" updateCMD = New SqlCommand(query, SQLconn) updateCMD.CommandType = CommandType.Text SQLconn.Open() updateCMD.ExecuteNonQuery() SQLconn.Close() End Sub Thanks

        M Offline
        M Offline
        Mayank Parmar
        wrote on last edited by
        #3

        Have you tried this : ---------------------------------------------- query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'"

        Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

        K 1 Reply Last reply
        0
        • M Mayank Parmar

          Have you tried this : ---------------------------------------------- query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'"

          Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

          K Offline
          K Offline
          kallileo
          wrote on last edited by
          #4

          The first method by szukuro worked... When I use this I get a error about converting data from char to integer probably because the data type in database is a Integer. query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'" Thanks guys.

          M 1 Reply Last reply
          0
          • K kallileo

            The first method by szukuro worked... When I use this I get a error about converting data from char to integer probably because the data type in database is a Integer. query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'" Thanks guys.

            M Offline
            M Offline
            Mayank Parmar
            wrote on last edited by
            #5

            When I use this I get a error about converting data from char to integer probably because the data type in database is a Integer. query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'" -------------------------------------------------------------------- Then you had to just reomve quotes. Like : query = "UPDATE [Temp] SET [value] = " + txt + " WHERE [name] = 'temprature'" --------------------------------------------------------------------

            Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

            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