Your application requires calling a stored procedure that retrieves a single value from the database. What steps would you follow to execute the stored procedure and retrieve the result?

  • Execute the stored procedure using SqlCommand.ExecuteNonQuery method, then retrieve the single value using SqlCommand.Parameters collection.
  • Execute the stored procedure using SqlCommand.ExecuteScalar method to directly retrieve the single value.
  • Use SqlCommand.ExecuteReader method to execute the stored procedure and retrieve the single value from SqlDataReader.
  • Use SqlDataAdapter to execute the stored procedure and retrieve the single value from DataSet.
SqlCommand.ExecuteScalar method is the correct option. It executes the query and returns the first column of the first row in the result set returned by the query. This method is typically used for executing commands such as SELECT statements that return a single value.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *