System.Data.SqlTypes.SqlNullValueException: 数据为空。不能对空值调用此方法或

有可能读出的数据为NULL,可以这样改:

方法一:
while (reader.Read())
{
for (int i = 0; i < 7; i++)
{
if (reader.IsDBNull(i))
{
continue;
}
readstring[i] = reader.GetString(i);
}
}
方法二:

string sql = "select ISNULL([Name],''),ISNULL([Address],''),ISNULL([WebAddress],''),ISNULL([Telephone],''),ISNULL([Description],''),ISNULL([LeftTopPic],''),ISNULL([LeftBottomPic],'') from [t_Customer] where [CustomerID] = " + ctid;

方法三:
while (reader.Read())
{
for (int i = 0; i < 7; i++)
{
readstring[i] = reader[i].ToString();
}
}

用 is DBNull 

如:
user.Phone = reader["phone"] is DBNull ? "" : (string)reader["phone"];
原文地址:https://www.cnblogs.com/yun007/p/3480285.html