I am trying to read a column type 'uniqueidentifier' in SQL with C#
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "SELECT templatename, subject, bodyhtml, sender, emailTemplateBodyFields.fieldid FROM emailTemplates left join emailtemplaterecipients on emailtemplates.emailtemplateid = emailtemplaterecipients.emailtemplateid left join emailTemplateBodyFields on emailtemplates.emailtemplateid = emailTemplateBodyFields.emailtemplateid WHERE emailtemplates.emailtemplateid = " + selectedEmailTemplateID;
myCommand.Connection = connection;
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
NewTemplateName = myReader.GetString(0);
NewSubject = myReader.GetString(1);
NewBodyHTML = myReader.GetString(2);
NewRecipients = myReader.GetString(3);
myRecipientList.Add(NewRecipients);
Guid tempGUID = myReader.GetGuid(4);
NewBodyFields = Convert.ToString(tempGUID);
myBodyList.Add(NewBodyFields);
However I am getting a null value exception, data is null on
Guid tempGUID = myReader.GetGuid(4);
When I run the statement in SQL Server, the column has no null values.
Please advise how to retrieve info from this column.
Thanks.