当前位置:编程学习 > C#/ASP.NET >>

System.NullReferenceException: 未将对象引用设置到对象的实例 那里出错了~~


行 127:        TableRow r = new TableRow();
行 128:        tblQiYeGuGan.Rows.Add(r);
行 129:            while (dr.Read())行 130:            {
行 131:                CurrentRowIndex = CellIndex / 3;
 


    protected void GenerateQiYeGuGanTable(Table tblQiYeGuGan)
    {
        string sql = "select top 9 GuGanId,GuGanName,PhotoOrigin from QYGuGan";
        sqlHelper.RunSQL(sql, out dr);
        int CellIndex = 0, CurrentRowIndex = 0, NewRowIndex = 0;
  
        TableRow r = new TableRow();
        tblQiYeGuGan.Rows.Add(r);
            while (dr.Read())
            {
                CurrentRowIndex = CellIndex / 3;
                TableCell td = new TableCell();
                td.CssClass = "SmallSquare";
                Image Img = new Image();
                Img.Width = new Unit("75px");
                Img.Height = new Unit("100px");
                Img.ImageUrl = dr["PhotoOrigin"].ToString();
                HyperLink hl = new HyperLink();
                hl.NavigateUrl = "ViewGuGanDetail.aspx?GuGanId=" + dr["GuGanId"].ToString();
                hl.Target = "_blank";
                hl.Controls.Add(Img);
                Literal ltNewLine = new Literal();
                ltNewLine.Text = "<br/><a href='ViewGuGanDetail.aspx?GuGanId="+dr["GuGanId"].ToString ()+"' target='_blank' >" + dr["GuGanName"].ToString() + "</a>";
                td.Controls.Add(hl);
                td.Controls.Add(ltNewLine);
                tblQiYeGuGan.Rows[CurrentRowIndex].Cells.Add(td);
                CellIndex++;
                NewRowIndex = CellIndex / 3;
                if (NewRowIndex > CurrentRowIndex)
                {
                    CurrentRowIndex = NewRowIndex;
                    TableRow nr = new TableRow();
                    tblQiYeGuGan.Rows.Add(nr);
                }
            }
        dr.Close();

    } --------------------编程问答-------------------- sqlHelper.RunSQL(sql, out dr); //执行结果 dr为null,你自己看看它有什么问题
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,