This is where the Public SqlDataReader getEmail is initialised.

public SqlDataReader getEmail(string UserName)
            if (conn.State.ToString() == "Closed")
            //string noemail ="noemailsaved";
            SqlCommand newCmd = conn.CreateCommand();
            newCmd.Connection = conn;
            newCmd.CommandType = CommandType.Text;
            newCmd.CommandText = "Select Email from dbo.EMPLOYEE where Username ='" + UserName + "'";
            SqlDataReader reader = newCmd.ExecuteReader();
            while (reader.Read())
                string email = reader["EMPLOYEE.Email"].ToString();

            return reader;

I'm using OOP and calling the function in asp.net page and want to display the value in a label. Below is the code I'm using to call the function.

SqlDataReader reader = dba.getEmail(pname);
lblEmail.Text = reader.ToString();

Instead of seeing the Email address of the Employee i'm seeing System.Data.SqlClient.SqlDataReader

Please help in correcting this error.

Thank you in advance.

Related posts

Recent Viewed