I am writing following code to update record but it is not updating. Please help me to solve this problem. Dim objcommand As SqlCommand ' Dim objtextbox As TextBox Dim str As String = "update my set age = @age where name = @name" objcommand = New SqlCommand(str, objconnection) objcommand.Parameters.Add(New SqlParameter("@age", SqlDbType.Int, 4)) objcommand.Parameters.Add(New SqlParameter("@name", SqlDbType.Char, 2)) objcommand.Parameters("@age").Value = TextBox2.Text objcommand.Parameters("@name").Value = TextBox1.Text objcommand.Connection = objconnection objcommand.Connection.Open() objcommand.ExecuteNonQuery()
Parameters.Add is a depreciated function, I would switch to .AddWithValue Dim objcommand As SqlCommand ' Dim objtextbox As TextBox Dim str As String = "update my set age = @age where name = @name" objcommand = New SqlCommand(str, objconnection) objcommand.Parameters.AddWithValue("@age", TextBox2.Text) objcommand.Parameters.AddWithValue("@name", TextBox1.Text) objcommand.Connection = objconnection objcommand.Connection.Open() objcommand.ExecuteNonQuery() objcommand.Connection.Close()