问题描述:

Been fighting this one for a while. Can someone tell me what I'm doing wrong?

Here is my C# object:

class FileObject

{

public int LocalInx { get; set; }

public byte[] File { get; set; }

public string FileName { get; set; }

}

Here is how I populate the byte array with a file:

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();

}

And here is how I add the row to the table. This is where I get an error.

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();

}

相关阅读:
Top