当我尝试下面的代码时,我收到了“运算符不存在:整数= @整数”和ArgumentException。
有人可以帮我解决这个问题吗?
public FileContentResult GetFile(int fileid)
{
NpgsqlDataReader rdr;
byte[] fileContent = null;
string mimeType=" ";
string fileName=" ";
NpgsqlConnection conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["portalconnectionstring"].ConnectionString);
using (portalconnectionstring ps = new portalconnectionstring())
{
var query = "select filename,content_type,filedata from tblfiles where fileid='"+fileid+"'";
var cmd = new NpgsqlCommand(query, conn);
cmd.Parameters.AddWithValue("@fileid", fileid);
conn.Open();
rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
rdr.Read();
fileContent=(byte[]) rdr["filedata"];
mimeType = rdr["content_type"].ToString();
fileName = rdr["filename"].ToString()
}
}
conn.Close();
return File(fileContent, mimeType, fileName);
}