I want a single SQL query to pick data from one table and update the second table with the data.
this is what I have done:
con1.Open()
Dim myReader As SqlDataReader = Nothing
dim one as string
Dim query As String = "select * from tblname where column1=@one"
Dim myCommand As New SqlCommand(query, con1)
myCommand.Parameters.AddWithValue("@one",one )
myReader = myCommand.ExecuteReader()
While myReader.Read()
Tbxorgan.Text = (myReader(0).ToString())
End While
con1.close
con1.open
Dim query1 As String = "UPDATE tblsign SET column2 = @col where username=@usen"
con1.Open()
Using cmd As New SqlCommand(query1, con1)
cmd.Parameters.AddWithValue("@col", Tbxorgana.Text)
cmd.Parameters.AddWithValue("@usen", user.text)
cmd.ExecuteNonQuery()
End Using
con1.Close()
It works fine but I dont want to be opening and closing the connection
Please help.