2

I am programming for a Windows Mobile 6.5 device.

I am using SQL Server Compact Edition, and am trying to write a byte stream to the database. The column type is image (which I understand can handle more than 8000 bytes), however I am getting the exception:

InvalidOperationException
@signature : Byte array truncation to a length of 8000.

Any idea why this is happening?

string sql = @"INSERT INTO E_CONS_SIGNATURE (CONS_NO, SIGNATURE, SIGNATURE_FORMAT, SIGNATURE_DATE)"
            + " VALUES(@consNo, @signature, @format, @date)";

SqlCeCommand cmd = new SqlCeCommand(sql, conn);
cmd.Parameters.AddWithValue("@consNo", txtConsignment.Text);
cmd.Parameters.AddWithValue("@signature", ms.ToArray());
cmd.Parameters.AddWithValue("@format", "BMP");
cmd.Parameters.AddWithValue("@date", new DateTime());

bool success = cmd.ExecuteNonQuery() > 0;

Storing on the file system is not an option at the moment.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lock
  • 5,422
  • 14
  • 66
  • 113

1 Answers1

0

On the error itself there is a problem on this line

cmd.Parameters.AddWithValue("@signature", ms.ToArray());

You need to convert your image to MemoryStream object.

Check the below site to help you.

Save images to SQL CE

Store an image in a SQL Server CE database

Regards

Community
  • 1
  • 1
BizApps
  • 6,048
  • 9
  • 40
  • 62