zoukankan      html  css  js  c++  java
  • 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"];
  • 相关阅读:
    001 分布式系统
    024 RabbitTemplate组件
    023 RabbitAdmin组件
    022 spring与Rabbitmq整合
    011 mandatory参数
    这样自己组装数据,醉了,
    cool,
    swift,
    page enable,
    构建 HTTPserver,
  • 原文地址:https://www.cnblogs.com/yun007/p/3480285.html
Copyright © 2011-2022 走看看