未将对象引用设置到对象的实例 怎么解决
做了一个 修改已经上传音乐的页面。在写绑定信息是 string _id = Request.QueryString["id"].ToString().Trim();这句总是提示 未将对象引用设置到对象的实例。请问怎么解决。
代码如下:
protected void PageInit()
{
string _id = Request.QueryString["id"].ToString().Trim(); _id = BasePage.CheckStr(_id);
tbMusicDal tbMusicDal1 = new tbMusicDal();
DataSet ds1 = tbMusicDal1.GetList(string.Format("id={0}", _id));
if(ds1.Tables[0].Rows.Count > 0)
{
DataRow dr = ds1.Tables[0].Rows[0];
tbName.Text = dr["Name"].ToString().Trim();
tbGroupName.Text = dr["Name"].ToString().Trim();
tbAuthors.Text = dr["Authors"].ToString().Trim();
tbLyrics.Text = dr["Contents"].ToString().Trim();
lb_path.Text = dr["MusicUrl"].ToString().Trim();
//绑定下拉列表
string strSql = "select * from tbMusicClass";
SqlDataAdapter sda = new SqlDataAdapter(strSql, BasePage.GetConn());
DataSet ds = new DataSet();
sda.Fill(ds, "tbMusicClass");
string _html = "<select id=\"selectClass\" name=\"selectClass\">";
foreach (DataRow draaa in ds.Tables[0].Rows)
{
if (dr["ParentId"].ToString().Trim() == draaa["id"].ToString().Trim())
{
_html += string.Format("<option value=\"{0}\" selected=\"selected\">{1}</option>", draaa["id"].ToString(), draaa["ClassName"].ToString());
}
else
{
_html += string.Format("<option value=\"{0}\">{1}</option>", draaa["id"].ToString(), draaa["ClassName"].ToString());
}
}
_html += "</select>";
ltr_class.Text = _html;
}
}
------解决方案--------------------string _id =string.Empty;
if (!string.IsNullOrEmpty(Request.QueryString["id"]))
_id = Request.QueryString["id"].ToString().Trim();
------解决方案--------------------string _id=string.Empty;
if (null != Request.QueryString["id"])
{
_id = Request.QueryString["id"].ToString().Trim();
}