已经和这个人打了一段时间了。有人能告诉我我做错了吗?
这是我的C#对象:
class FileObject
{
public int LocalInx { get; set; }
public byte[] File { get; set; }
public string FileName { get; set; }
}
以下是我用文件填充字节数组的方法:
var FO = new FileObject();
FO.LocalInx = LocalInx;
FileInfo fi = new FileInfo(ti.Name);
FO.FileName = fi.Name;
FileStream fs = File.OpenRead(ti.Name);
try
{
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,Convert.ToInt32(fs.Length));
fs.Close();
FO.File = bytes;
}
finally
{
fs.Close();
}
以下是我如何将行添加到表中。这是我收到错误的地方。
if (o is FileObject)
{
var fpc = new SqlCeCommand("insert into Files (File, UtilityMap, NotApplicable, LocalInx, FileName) values (@File, 1, 0, @LocalInx, @FileName)", con);
fpc.Parameters.Add("@File", SqlDbType.VarBinary, 8000).Value = ((FileObject)o).File;
fpc.Parameters.AddWithValue("@LocalInx",((FileObject)o).LocalInx);
fpc.Parameters.AddWithValue("@FileName", ((FileObject)o).FileName);
fpc.ExecuteNonQuery();
}