how to convert null to empty string in stored procedure?

I have the following stored procedure (pretty straight forward):

CREATE PROCEDURE usp_GetBioDemData
@uid      nvarchar(255)
AS
SELECT firstname, mid_name, lastname, maiden_firstname, maiden_lastname, maiden_middlename, mail_label, nickname FROM ALUM_UNIV_ID_V
      WHERE uid = @uid
GO

I am using the following C# code to retrieve the results:

        try
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow);

            //Get the first row.
            reader.Read();
            AlumniProfile ap = new AlumniProfile((string)reader["firstname"], (string)reader["lastname"],
                (string)reader["mid_name"], (string)reader["maiden_firstname"], (string)reader["maiden_lastname"],
                (string)reader["maiden_middlename"], (string)reader["mail_label"], (string)reader["nickname"]);
            reader.Close();
            return ap;
        }

The problem is, if one of the fields is null, then trying to do a (string)reader["fieldname"] will return an error.

How can I change the stored procedure to check for null fields and then return, maybe an emptry string, if it finds one so that the cast to string in the C# code doesn't throw an error. Or would you suggest I do that checking in the C# code and leave the stored procedure as it is?
IUAATechAsked:
Who is Participating?
 
ptjcbConnect With a Mentor Commented:
SELECT ISNULL(firstname, '') firstname, ISNULL(mid_name,'') mid_name, ISNULL(lastname,'') lastname, ISNULL(maiden_firstname,'') maiden_firstname, ISNULL(maiden_lastname,'') maiden_lastname, ISNULL(maiden_middlename,'') maiden_middlename, ISNULL( mail_label, '') mail_label, ISNULL(nickname,'') nickname FROM ALUM_UNIV_ID_V
     WHERE uid = @uid
0
 
IUAATechAuthor Commented:
that was easy :)

thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.