未将对象引用设置到对象的实例
using System;using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
public partial class _13_11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
//创建datatable对像
DataTable dt = new DataTable("t_aritcle");
//创建列
DataColumn dtc=new DataColumn ("文章id",typeof(Int32));
dt.Columns.Add(dtc);
dtc = new DataColumn("标题", typeof(string));
dt.Columns.Add(dtc);
dtc = new DataColumn("作者", typeof(string));
dt.Columns.Add(dtc);
// 添加数据到datatable中
DataRow dtr = dt.NewRow();
dtr["文章id"]=1;
dtr["标题"]="天降冰雹";
dtr["作者"]="王二";
dt.Rows .Add (dtr);
dtr=dt.NewRow ();
dtr ["文章id"]=2;
dtr ["标题"]="中大奖了";
dtr["作者"] = "幽忧";
//添加到dataset中
ds.Tables .Add (dt);
//绑定到gridview
GridView1.DataSource=ds.Tables ["t_article"].DefaultView;
GridView1.DataBind();
}
}
GridView1.DataSource=ds.Tables ["t_article"].DefaultView;
这名出现:未将对象引用设置到对象的实例,请各位帮我查看一下,谢了。