TextBox.text as parameter in query
-
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
-
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
-
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
Have you tried this : ---------------------------------------------- query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'"
Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India
-
Have you tried this : ---------------------------------------------- query = "UPDATE [Temp] SET [value] = '" + txt + "' WHERE [name] = 'temprature'"
Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India
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.
-
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.
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