以下是效果,就是如果数据库id字段==null,那么就跳转到GsjjInsert.aspx,否则不等于null就跳转到GsjjSelect.aspx
但问题是如果id没数据的话就报错啊。怎么办啊?protected void Page_Load(object sender, EventArgs e)
    {
        string sqlselect = "select * from q_gsjj";
        DataSet ds = db.GetDS(sqlselect);
        if (ds.Tables[0].Rows[0]["id"].ToString() == null)//在位置 0 处没有任何行。
        {
            Response.Redirect("GsjjInsert.aspx");
        }
        else
        {
            Response.Redirect("GsjjSelect.aspx");
        }
    }

解决方案 »

  1.   

    我不ToString也不行啊,同样的错误
      

  2.   

    是的,在做判断,如果数据库id==null,就跳转页面
      

  3.   

    ds.Tables[0]没任何数据 你判断ds.Tables[0]. 是不是为NULL 或者count 是否>0
      

  4.   


    加个判断
    if(ds.table[0].Rows.Count>0)
    {
       ///
    }
      

  5.   

    table.Rows.Count > 0 判断表中是否存在数据table.Rows[rowIndex][columnIndex] == null 判断指定行/列的值是否为 null只有 table.Rows[rowIndex][columnIndex] != null 时才能
    table.Rows[rowIndex][columnIndex].ToString() 或者Convert.To指定类型(table.Rows[rowIndex][columnIndex])
      

  6.   


    if(ds.Tables.Rows.Count>0 && ds.Tables[0].Rows.Count>0)
    {
     if (ds.Tables[0].Rows[0]["id"].ToString() == null)//在位置 0 处没有任何行。
            {
                Response.Redirect("GsjjInsert.aspx");
            }
            else
            {
                Response.Redirect("GsjjSelect.aspx");
            }
    }
      

  7.   

        protected void Page_Load(object sender, EventArgs e)
        {
            string sqlselect = "select * from q_gsjj";
            DataSet ds = db.GetDS(sqlselect);
            if(ds.Tables[0].Rows.Count>0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString().length>0)
                  {
                    Response.Redirect("GsjjSelect.aspx");
                }
                else
                {
                    Response.Redirect("GsjjInsert.aspx");
                }
            }
            else
            {
                 Response.Write("<script>alert('No Data!')</script>");
            }
        }首先,要考虑此时数据库中是否存在数据;其次,才是id值是否存在
    而且我有一个地方不太明白,因为你是无条件查询,可能会存在第一行的id为空,后面的id不为空,你不能仅因为第一行的id就判断它是进入哪个页面吧?或者你可以如下做法:    protected void Page_Load(object sender, EventArgs e)
        {
            string sqlselect = "select * from q_gsjj where id is not null";
            DataSet ds = db.GetDS(sqlselect);
            if(ds.Tables[0].Rows.Count>0)
            {
                Response.Redirect("GsjjSelect.aspx");
            }
            else
            {
                Response.Redirect("GsjjInsert.aspx");
            }
        }
      

  8.   

    你没读到值,就没有行
    ds.Tables[0].Rows[0]["id"]  这个是在读第一行啊肯定不行啊加个
    if(ds.Tables[0].Rows.Count>0)
     
    就行了