有可能读出的数据为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"];

相关文章:

  • 2021-11-03
  • 2022-01-06
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
  • 2022-12-23
相关资源
相似解决方案