“未将对象引用设置到对象的实例。”
报这个错是因为Request.QueryString["BookID"]不存在,
string BookID= "";if (Request.QueryString["BookID"] != null)
{
BookID= Request.QueryString["BookID"].ToString();}
这样写就可以了

解决方案 »

  1.   

    偶用了好多URL传值,单个页面运行会报“未将对象引用设置到对象的实例
    ===============================================
    传值的语句?获取索引时报“索引超出范围。必须为非负值并小于集合大小。参数名: index” 
    hoppingCars sc = (ShoppingCars)this.dlShopCart.DataKeys[e.Item.ItemIndex];
    ================================================
    没有设置DataList的DataKeyField属性
      

  2.   

    if (Request.QueryString["BookID"] != null && Request.QueryString["VoiceID"] == null)
            {
                ID = Request.QueryString["BookID"].ToString();
            }
            else
            {            ID = Request.QueryString["VoiceID"].ToString();
            }
    就是这句话报错
      

  3.   

    else中
    if(Request.QueryString["BookID"] == null && Request.QueryString["VoiceID"] == null)
    运行ID = Request.QueryString["VoiceID"].ToString();就错了
    “未将对象引用设置到对象的实例。”