Click here to Skip to main content
15,031,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

I think you can use a stored procedure to perform these two tasks and in command of the connection simply run the procedure parameters.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900