PhotoRID = reader["RID"].ToString();什么意思啊,怎么和函数的参数相同

解决方案 »

  1.   

    我是想把从表里面读出来的RID给共有变量PhotoRID
      

  2.   

    还是不行啊!
    我已经换了个变量!
    我觉得可能是我的sql语句有问题,但是我就是 不知道错在哪里了!
      

  3.   

    cmd.Parameters.AddWithValue("@PhotoRID", PhotoRID);没给参数赋值
      

  4.   

    我已经把传入的变量的值赋值给了@PhotoRID了啊!怎么会没有查询结果呢!我在SQL server里面建立查询时用值38替换@PhotoRID做查询时能够返回正确的结果的啊!难道我这样赋值是错误的?
      

  5.   

    debug --> attach to process
    ok在using 断点试试
      

  6.   

    越界错误,楼主的异常真的是这里抛出来的?
    PhotoRID = reader["RID"].ToString();
    唯一有可能抛这个异常的就在这里了
    reader["RID"]
    不过上面既然是
    SELECT TOP 1 [RID]
    这个列应该是有的,否则SQL异常
    楼主再查
      

  7.   

    public void GetRestaurantListPhoto()
        { 
            string sql = "";
          
       
            try
            {            sql = "SELECT TOP 1 [RID] FROM [Resturant] ORDER BY [RNumber] desc";
                myconnection.Open();
                SqlCommand cmd = new SqlCommand(sql, myconnection);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                       PhotoRID= reader["RID"].ToString();
                
                    }
                }
                       }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            finally
            {
                myconnection.Close();
            }        for ( int i=0; i<10||PhotoRID==null; i++)
            {
                //GetRestaurantListRID(PhotoRID);            
                GetRestaurantListPic(PhotoRID,i);            PicRID[i] = PhotoRID;
            
         
                GetRIDdesc(PhotoRID);          }
        }
      

  8.   

    我是在这个函数里面调用了之前出现错误的函数,GetRestaurantListPic(PhotoRID,i)这个函数是将ID号为PhotoRID的图片信息读出来.我只要读出前十个就可以了,所以做了个循环!i从0-9将结果存在一个数组里面!
      

  9.   

    // PicRID 系虾米东东?
    // PicRID.Length > 5 ????PicRID[i] = PhotoRID;  // 应该是这里出错啦 ....
      

  10.   

    cmd.Parameters.AddWithValue("@PhotoRID", PhotoRID);
    改成cmd.Parameters.Add("@PhotoRID",photoRID)如果还不行就
    raeder["RID"] 改成 reader[0]
      

  11.   

    楼主你调用GetRIDdesc这个函数时候,传的值是多少?
      

  12.   

    传的值是从表中读出的最新入库的ID号,然后通过GetRIDdesc函数得到数据表中比这个ID号小的最新的ID号,通过这个ID号再到图片表里面找到相应的图片信息,通过TOP 1来限定选出ID号相符的多张图片中的一张!
      

  13.   

    cmd.Parameters.AddWithValue("@PhotoRID", PhotoRID);
    这一句是正确的!我执行的时候能够正确的取到前5个值!但是当取第6个的时候就出现越界的异常!
      

  14.   

    public void GetRestaurantListPhoto()
        { 
            string sql = "";
          
       
            try
            {            sql = "SELECT TOP 1 [RID] FROM [Resturant] ORDER BY [RNumber] desc";
                myconnection.Open();
                SqlCommand cmd = new SqlCommand(sql, myconnection);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                       PhotoRID= reader["RID"].ToString();
                
                    }
                }
                       }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            finally
            {
                myconnection.Close();
            }        for ( int i=0; i<10||PhotoRID==null; i++)
            {
              
                
                GetRestaurantListPic(PhotoRID,i);            PicRID[i] = PhotoRID;
            
         
                GetRIDdesc(PhotoRID);          }
        }
        //得到LIST页店家图片的最新的店家ID
        public void GetRIDdesc(string PhoRID)
        {
            string sql = "";
       
           try
            {
                sql = "SELECT TOP 1 [RID] FROM [Resturant] where RID< @PhotoRID ORDER BY RID DESC";
                myconnection.Open();
                SqlCommand cmd = new SqlCommand(sql, myconnection);
                cmd.Parameters.AddWithValue("@PhotoRID", PhoRID);
              
               
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        PhotoRID = reader["RID"].ToString();
                 
                    }
                }        }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            finally
            {
                myconnection.Close();
            }    }
        //LIST页显示时,获得最新入库的图片
        public void GetRestaurantListPic(string PhotoRID,int i)
        {
            string sql = "";
            try
            {            ORID = OtherRID[i].ToString();
                sql = "SELECT TOP 1 [RPhoto] FROM [RestaurantPhoto] where RID=@PhotoRID";
                myconnection.Open();
                SqlCommand cmd = new SqlCommand(sql, myconnection);
                cmd.Parameters.AddWithValue("@PhotoRID", PhotoRID);            using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        RestaurantPhotoList[i] = reader["RPhoto"].ToString();                }
                }        }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
            finally
            {
                myconnection.Close();
            }
        }
      

  15.   

    这是我完整的代码,OtherRID为长度为10的共有数组变量。
    我有两个表,一个是存放基本信息的Restaurant表,还有一个存放图片的RestaurantPhoto表。因为一个Restaurant的ID对应多张图片,我又要读出按照ID号逆序,也就是最新入库的ID对应的一张图片!
    GetRestaurantListPhoto这个函数中我先读出最新入库的ID号,然后调用GetRestaurantListPic函数来读出这个ID所对应的一个图片信息,然后把这个图片的信息存到数组PicRID中,(这是个长度为10的数组,公有变量)。再通过GetRIDdesc函数得到比这个ID小的所有ID中最新入库的ID号,循环读出十个!
      

  16.   

    while (reader.Read())
                    {
                       PhotoRID= reader["RID"].ToString();
                
                    }其中 PhotoRID 是什么类型,不是集合的话,为什么用循环?
      

  17.   

    My-Blog地址1:http://www.cnblogs.com/nyzfl
    My-Blog地址2: http://blog.csdn.net/nyzfl
      

  18.   

    while (reader.Read())

      for(int i=0;i<reader.FieldCount;i++)
    {
        PhotoRID =+PhotoRID;
    }}
    myReader.Close();
      

  19.   

    为什么用SqlDataReader ?用DataTable就不会出现这样的问题
      

  20.   

    for ( int i=0; i<10||PhotoRID==null; i++)
            {
              
                
                GetRestaurantListPic(PhotoRID,i);            PicRID[i] = PhotoRID;//问题可能在这里,i=0-9;你确保PicRID.Length至少是10
                                     //或者  i<10||PhotoRID==null 第2个条件一直为true导致i == 10
         
                GetRIDdesc(PhotoRID);          }
      

  21.   

    RestaurantPhotoList[i]
    这个也要确保Lenth >= 10;
      

  22.   

    catch (Exception err)
            {
                throw new Exception(err.Message);
            }
    看了这段代码,就知道楼主是个新手,捕获一个异常又抛出,lz想想这段代码除了浪费性能还有什么其他作用吗?