dr.read()
string path = dr["ImageUrl"].ToString();
System.Drawing.Image oImage = System.Drawing.Image.FromFile(path);
会出现“在没有任何数据时进行无效的读取”的错误如果改为
if (dr.Read())
{
  string path = dr["ImageUrl"].ToString();
}
System.Drawing.Image oImage = System.Drawing.Image.FromFile(path);
------------
就会出现FromFile(path)的path没定义。请问大大们如何把里面参数取出来?

解决方案 »

  1.   

    string path;
    if (dr.Read()) 

      path = dr["ImageUrl"].ToString(); 

    System.Drawing.Image oImage = System.Drawing.Image.FromFile(path); 
      

  2.   

    string path = string.Empty;
    if (dr.Read()) 

      path = dr["ImageUrl"].ToString(); 
    } if(!string.IsNullOrEmpty(path))
    System.Drawing.Image oImage = System.Drawing.Image.FromFile(path); 
      

  3.   

    string path="";
    if (dr.Read()) 

      path = dr["ImageUrl"].ToString(); 

    System.Drawing.Image oImage = System.Drawing.Image.FromFile(path); 
      

  4.   

    你前面的查询没有返回结果,导致if (dr.Read()) 为假,没有进入path 付值
    你看看SQL语句,直接执行返回什么内容
    或将相关代码也贴出来帮你看看