How to catch result set in code view
I created this stored procedure.
CREATE PROCEDURE PersonAssign
(
@PersonID int
)
BEGIN
Update Register set Status = '开发者_开发技巧true' where PersonID = @PersonID;
SELECT * FROM Register
END
Now, I want to get result set in vb.net by using ADO.net. How can I catch this. Please help me.
I would probably create a sqlcommand object, connect to the database, executeReader and return a sqldatareader object. There a bunch of other ways to do this depending on what you want to do with the data. Please be more specific if you aren't looking for a general idea.
Try
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim dr As New SqlDataReader()
Try
con.ConnectionString = Settings.ConnectionString
con.Open()
cmd.Connection = con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "PersonAssign"
cmd.Parameters.Add("@PersonID", SqlDbType.Int)
cmd.Parameters("@PersonID").Value = -Parameter-value-
dr = cmd.ExecuteReader()
' Do something with dr
Catch e As Exception
End Try
精彩评论