SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["Connstr"]);
        string   SQL = "select ImageUrl from gonggaoxinxi where zhanhui_id='" + e.CommandName + "'";   
        SqlCommand   cmd   =   new   SqlCommand(SQL,mycon);   
        cmd.CommandType   =   CommandType.StoredProcedure;   
        cmd.Parameters.Add("@zhanhui_id",SqlDbType.Int);
        cmd.Parameters["@zhanhui_id"].Value   = SQL;
        mycon.Open();
        string filePath = @"images\NewsPic\" + cmd.ExecuteScalar().ToString();
        if(File.Exists(filePath))          
        {   
            File.Delete(filePath)   ;   
        }   

解决方案 »

  1.   

               SqlConnection   mycon   =   new   SqlConnection(ConfigurationManager.AppSettings["Connstr"]); 
                    string       SQL   =   "select   ImageUrl   from   gonggaoxinxi   where   zhanhui_id=@zhanhui_id";       
                    SqlCommand       cmd       =       new       SqlCommand(SQL,mycon);       
                    cmd.CommandType       =       CommandType.StoredProcedure;       
                    cmd.Parameters.Add("@zhanhui_id",SqlDbType.Int); 
                    cmd.Parameters["@zhanhui_id"].Value       =  e.CommandName; 
                    mycon.Open(); 
                    string   filePath   =   @"images\NewsPic\"   +   cmd.ExecuteScalar().ToString(); 
                    if(File.Exists(filePath))                     
                    {       
                            File.Delete(filePath)       ;       
                    } 
      

  2.   

    cmd.CommandType               =               CommandType.Text;   
      

  3.   

    什么错误? 也不说? 看看filePath得到的是什么?? 最可能的是路径不对。
      

  4.   

       cmd.Parameters["@zhanhui_id"].Value       =   SQL; 不好意思,昨天发完贴忘记了,是上面这行错误