日期:2014-05-17  浏览次数:20621 次

sql语句内的filename标量未声明
 public List<GraduateFileLook> SearchGraduateFile(string FileName, string UploadClassification)
 {
   
    SqlParameter[] parameter = {
     new SqlParameter("@FileName", SqlDbType.NVarChar,50),
     new SqlParameter("@UploadClassification", SqlDbType.NVarChar,50)
     };
    parameter[0].Value = FileName;
    parameter[1].Value = UploadClassification;
    string sql = @"SELECT GraduateFileUpload.FileName,GraduateFileUpload.UploadClassification,GraduateFileUpload.Remark 
    FROM GraduateFileUpload WHERE GraduateFileUpload.FileName = @FileName AND GraduateFileUpload.UploadClassification = @UploadClassification";
    List<GraduateFileLook> GraduateFileLookList = new List<GraduateFileLook>();
    using (SqlDataReader gfl = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, sql, null))
    {
while (gfl.Read())
{
 GraduateFileLook GraduateFileLook = new GraduateFileLook
 {
FileName = gfl["FileName"].ToString(),
UploadClassification = gfl["UploadClassification"].ToString(),
Remark = gfl["Remark"].ToString()
  };
    GraduateFileLookList.Add(GraduateFileLook);
}
gfl.Close();
    }
    return GraduateFileLookList;
    
}


运行后提示“为生命变量@FileName”,就是这个错误。求指导。

------解决方案--------------------
using (SqlDataReader gfl = SqlHelper.ExecuteReader(SqlHelper.ConnectionString, CommandType.Text, sql, null)) //这里的null是否应该为parameter?