日期:2014-05-18  浏览次数:20486 次

求 DataSet.Tables["表名"].DefaultView的用法 !!!!!!!!!!!
程序代码如下:
public   DataGrid   MyList_1;
DataSet   ds   =   new   DataSet();
oleAp1.Fill(ds,   "contents ");
MyList_1.DataSource   =   ds.Tables[ "contents "].DefaultView;(就是这句出错)

报错信息如下:
异常详细信息:   System.NullReferenceException:   未将对象引用设置到对象的实例

------解决方案--------------------
public DataGrid MyList_1;
DataSet ds = new DataSet();
oleAp1.Fill(ds, "contents ");
if(ds!=null&&ds.Tables[ "contents "].Rows.Count> 0)
{
MyList_1.DataSource = ds.Tables[ "contents "].DefaultView;
}

------解决方案--------------------
ds 没有数据