public class logic : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid d_grid2;
private datab dg_tmp = new datab();
private DataView dv = new DataView();
public void Page_Load(object sender,System.EventArgs e)
{
dv=dg_tmp.tb_grid();
d_grid2.DataSource=dv;
d_grid2.DataBind();
}
}public class datab
{
public DataView tb_grid()
{
string strcon="server=localhost;database=stu2;user id=sa;password=1111";
SqlConnection conn= new SqlConnection(strcon);
DataSet ds =new DataSet();
SqlDataAdapter da =new SqlDataAdapter();
da.SelectCommand.CommandText="sysRefresh";
da.SelectCommand.CommandType=CommandType.StoredProcedure;
da.SelectCommand.Connection.Open();
da.SelectCommand.ExecuteNonQuery();
da.Fill(ds,"ThisTab");
da.SelectCommand.Connection.Close();
if(ds!=null)
return ds.Tables["ThisTab"].DefaultView;
}
}浏览时,提示
Object reference not set to an instance of an object.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
stu3.b.datab.tb_grid() +85
stu3.a.logic.Page_Load(Object sender, EventArgs e) +16
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731请能者帮小弟!谢谢!
{
protected System.Web.UI.WebControls.DataGrid d_grid2;
private datab dg_tmp = new datab();
private DataView dv = new DataView();
public void Page_Load(object sender,System.EventArgs e)
{
dv=dg_tmp.tb_grid();
d_grid2.DataSource=dv;
d_grid2.DataBind();
}
}public class datab
{
public DataView tb_grid()
{
string strcon="server=localhost;database=stu2;user id=sa;password=1111";
SqlConnection conn= new SqlConnection(strcon);
DataSet ds =new DataSet();
SqlDataAdapter da =new SqlDataAdapter();
da.SelectCommand.CommandText="sysRefresh";
da.SelectCommand.CommandType=CommandType.StoredProcedure;
da.SelectCommand.Connection.Open();
da.SelectCommand.ExecuteNonQuery();
da.Fill(ds,"ThisTab");
da.SelectCommand.Connection.Close();
if(ds!=null)
return ds.Tables["ThisTab"].DefaultView;
}
}浏览时,提示
Object reference not set to an instance of an object.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
stu3.b.datab.tb_grid() +85
stu3.a.logic.Page_Load(Object sender, EventArgs e) +16
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731请能者帮小弟!谢谢!
解决方案 »
- 关于FusionCharts 急急、、、
- 为什么静态类不能实现接口?
- 请问大家,我的网站有四个不同类别的类容,在设计数据库的时候,我是建立四个表每个表一个类别的类容好,还是只要一个表每个类别设立一个类别标志位好?
- 以前看到过一篇文章,讲如何在vs2005中调试ASP程序,现在找不到了,大家谁知道,100分!
- 求教验证码的问题
- 求助
- 关于鼠标放置在某图标时变成另一个图标
- 怪了,我的iis里的应用程序配置无法添加扩展名映射
- 怎么提高wenservice的性能?
- 哪位知道哪里有Microsoft Content Management Server下载?
- 本人现在做的项目有个电子地图功能需要实现,其要求如下:
- 关于TreeView的一个问题。各位不吝赐教
是有问题的,改写成下面这样吧:
public DataView tb_grid()
{
string strcon="server=localhost;database=stu2;user id=sa;password=1111";
SqlConnection conn= new SqlConnection(strcon);
SqlCommand cm = new SqlCommand("sysRefresh",conn);
cm.CommandType=CommandType.StoredProcedure;
SqlDataAdapter da =new SqlDataAdapter(cm);
DataTable dt = new DataTable();
conn.Open();
da.Fill(dt);
conn.Close();
DataView dv =dt.DefaultView;
return dv;
}
{
.....
}
这是一个类,当创建一个此类的实例时,此动作叫做“实例化”,例如DataSet ds =new DataSet();就是创建了一个DataSet类的实例ds
lz的问题:
SqlDataAdapter da =new SqlDataAdapter(); 这只创建了一个SqlDataAdapter的实例,并不要理所当然地去访问它的任何属性,因为有可能仍然是个空的对象,SelectCommand就是,所以报错
用你的方法试过,出现错误:
The SelectCommand property has not been initialized before calling 'Fill'.
{
string strcon="server=localhost;database=stu2;user id=sa;password=1111";
SqlConnection conn= new SqlConnection(strcon);
SqlCommand cm = new SqlCommand("sysRefresh",conn);
cm.CommandType=CommandType.StoredProcedure;
conn.Open();
SqlDataAdapter da =new SqlDataAdapter(cm);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
DataView dv =dt.DefaultView;
return dv;
}
这样看看呢