public void data_qry(object sender, System.EventArgs e)
{

DataView dv=new DataView();
         Table1.Visible=false;
dv=(DataView)Session["dv"];//取得dv
string a="country='"+ txt_country.Text.Trim()+" '";//设定查询语句的字段名等于界面输入的内容
dv.RowFilter=a;//??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
//判断查询记录是否有记录
if(dv.Count>0)
{
   Table1.Visible=true;
dv.Sort=drop_index.SelectedItem.Value;
display();
}
            
   
}
最有可能的“System.NullReferenceException”类型的异常出现在 bbc.dll 中其他信息: 未将对象引用设置到对象的实例。

解决方案 »

  1.   

    public void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    SqlConnection conn=new SqlConnection("Server=localhost; User Id=sa; Pwd=vcdvcd; DataBase=Northwind");
    conn.Open();
    SqlCommand cmd=new SqlCommand();
    cmd.Connection=conn;
    cmd.CommandText="Select * from Customers";
    SqlDataAdapter da=new SqlDataAdapter();
    da.SelectCommand=cmd;
    DataSet ds=new DataSet();
    da.Fill(ds,"Customers");
    DataView dv=new DataView();
    dv.Table=ds.Tables["Customers"];
    dv.AllowDelete=true;
    dv.AllowEdit=true;
    dv.AllowNew=true;
    Session["dv"]=dv;//dv add to session
    }
    }
      

  2.   

    你在使用dv的时候,先判断一下dv是否为空。