System.NullReferenceException: 未将对象引用设置到对象的实例。

[复制链接]
查看11 | 回复1 | 2011-7-30 11:42:37 | 显示全部楼层 |阅读模式
if(!Page.IsPostBack)

{

string PetTypeID=Request.QueryString["typeID"].ToString();

SqlConnection con = DB.createCon();

con.Open();

SqlCommand cmd = new SqlCommand("select petTypeName from petType where petTypeID='"+PetTypeID+"'",con);

this.Label1.Text = Convert.ToString(cmd.ExecuteScalar());

cmd.CommandText = "select * from petInfo where petTypeID='"+PetTypeID+"'";

SqlDataReader sdr = cmd.ExecuteReader();

this.GridView1.DataSource = sdr;

this.GridView1.DataBind();

}
源错误:
行 20:
if(!Page.IsPostBack)
行 21:
{
行 22:
string PetTypeID=Request.QueryString["typeID"].ToString();
行 23:
SqlConnection con = DB.createCon();
行 24:
con.Open();

急需,望指点!!!

回复

使用道具 举报

千问 | 2011-7-30 11:42:37 | 显示全部楼层
前一个页面是否传过来了typeid比如url的链接是xxx.aspx?typeid=123...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行