String strCount = "select count(1)  from (" + strSql + ") a ";        int iCount = 0;
        SqlCommand cmdCount = new SqlCommand(strSql,conn);
        dtr = cmdCount.ExecuteReader();
        if (dtr.Read())
        {            iCount = dtr.GetInt32(0);此处老是提示指定的转换无效,我的数据库是SQLserver        }

解决方案 »

  1.   

    select count(1)  from (" + strSql + ") a 
    是不是字段的值是null  
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    select count(1)  from (" + strSql + ") a 执行后不是空的,只是字段名是空的,但字段的值不为空,有一条记录.
      

  3.   

    iCount = Convert.ToInt32(dtr.GetInt32(0).toString());
      

  4.   

    object oo = dtr[0];
    看看这里是值是多少.
      

  5.   

    刚才查到是数据库没连上的原因,但是这样写不对吗: SqlConnection conn = new SqlConnection();
            String strConn = "server=chenzj;database=lbwl;uid=sa;pwd=";
            conn.ConnectionString = strConn;
            conn.Open();
            SqlCommand cmd = new SqlCommand("select * from pro_menu", conn);
            SqlDataReader dtr = cmd.ExecuteReader();
            Response.Write(dtr[1].ToString());
    现在这样写返回的结果是空的,说明没有连上数据库,不知道是为什么?
      

  6.   

    // open conn ....
    String strCount = "select count(1)  from (" + strSql + ") a ";        int iCount = 0;
            SqlCommand cmdCount = new SqlCommand(strSql,conn);
            object o = cmdCount.ExecuteScalar();
            
                iCount = Convert.ToInt32(o);
      

  7.   

    if (dtr.Read())
            {            Response.Write(dtr[1].ToString());        }
      

  8.   

    使用DataReader时。注意if (dtr.Read())
    {
      
    }
      

  9.   

    iCount = dtr.GetInt32(0);此处老是提示指定的转换无效,我的数据库是SQLserver那是因为的第一列的数据类型不符。