fada397 0 Newbie Poster

below is the code which select value from the database and increase it by 2 and update the database with the new value.
how do I lock or prevent multiple read and update at the same time? please help

Dim query2 As String = "select * from " + usern + " where id=@selcand " 'select value from database
Dim myCommand2 As New SqlCommand(query2, con1)
myCommand2.Parameters.AddWithValue("@selcand", tbxcand.text)
myReader2 = myCommand2.ExecuteReader()
While myReader2.Read()
Session("tov") = myReader2(5)
End While
con1.Close()


Session("tov") += 2 'increase value by 2

con1.Open() 'update database with the new value
Dim query As String = "UPDATE " + usern + " SET tovs = @tov where id= @selcand"
Using cmd As New SqlCommand(query, con1)
cmd.Parameters.AddWithValue("@selcand", lbxselectdcand.SelectedItem.ToString)
cmd.Parameters.AddWithValue("@tov", Session("tov"))

cmd.ExecuteNonQuery()
con1.Close()