I am having a strange message displayed on the asp:label when trying to display data from a database. During page_load the asp:label is meant to be populated from a datasource however is displays the following message/text “System.Data.SqlClient.SqlDataReader”
What could be causing this?
I have written a small method in the page load of the .aspx.cs page.
labelName is the one which is displaying this message:
public partial class edit_questionnaire : System.Web.UI.Page
{
OsqarSQL GetData;
protected void Page_Load(object sender, EventArgs e)
{
string questionnaireId = Session["qID"].ToString();
int qid = Convert.ToInt32(questionnaireId);
GetData = new OsqarSQL();
string name = GetData.GetQuestionnaireName(qid);
labelName.Text = name;
}
}
Which calls the following method:
public string GetQuestionnaireName(int questionnaireId)
{
string returnValue = string.Empty;
SqlCommand myCommand = new SqlCommand("GetQuestionnaireName", _productConn);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add(new SqlParameter("@QUEST_ID", SqlDbType.Int));
myCommand.Parameters[0].Value = questionnaireId;
SqlDataReader qName = getData(myCommand);
while (qName.Read())
{
returnValue = qName.ToString();
}
_productConn.Close();
return returnValue;
}
And uses this stored procedure:
ALTER PROCEDURE [hgomez].[GetQuestionnaireName]
(
@QUEST_ID int
)
AS
/*SET NOCOUNT ON;*/
SELECT QuestionnaireName FROM [Questionnaires] WHERE QuestionnaireID = @QUEST_ID
RETURN
You were assigning the SqlDataReader to your returnValue rather than reading the value.