我正在尝试使用 C# 在 SQL 中读取列类型“uniqueidentifier”
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);
但是我得到一个空值异常,数据为空
Guid tempGUID = myReader.GetGuid(4);
当我在 SQL Server 中运行该语句时,该列没有空值。
请告知如何从此列中检索信息。
谢谢。