Monday, April 12, 2010

Stored Procedure Output Parameters to Retrieve a Single Row


conn.Open();
SqlDataReader reader = cmd.ExecuteReader();

if (reader.HasRows)
{
    poll = new Poll();

    poll.Id = (int)cmd.Parameters[“@ID”].Value;
    poll.Question = (string)cmd.Parameters[“@Question”].Value;
    poll.DatePosted = (DateTime)cmd.Parameters[“@date”].Value;

    while (reader.Read())
    {
       
    }

    reader.Close();
}
else
{
    reader.Close();
}




Stored Procedure For that

DECLARE @ID         INT
DECLARE @Question   VARCHAR(128)
DECLARE @Date    DATETIME

EXEC db_Polls_GetCurrentPoll
    @ID OUTPUT,
    @Question OUTPUT,
    @Date OUTPUT

SELECT @ID AS ' ID'
SELECT @Question AS
SELECT @DateAS 'Date Posted'

Action Method in Mvc

In this section, you will learn about the action method of controller class. All the public methods of a Controller class are called Act...