Binary field in SqlCE

  • Thread starter Thread starter Adam Goetz
  • Start date Start date
A

Adam Goetz

I hope that I'm close with what I currently have :

trying save the data

command.CommandText = "UPDATE ConTable SET imagesignature = ? WHERE ConValue
= '" + sConValue + "';";
command.Parameters.Add("@imagesignature", SqlDbType.Image);
command.Parameters["@imagesignature"].Value = binSignature;
command.ExecuteNonQuery();

try to read the data back

sqlSelectTable.CommandText = "SELECT * from ConTable where ConValue = '" +
sConVlaue + "'";
SqlCeDataReader selectreader = sqlSelectTable.ExecuteReader();
if (selectreader.Read())
{
binSignature = selectreader.GetSqlBinary(ImageField);
};


My save appears to work - it doesn't exception and the SqlCe Query Analyser
shows that the field is non-null - though it doesn't show any data from the
field. Yes there is information in binSignature which is of type SqlBinary.
My load gives a binSignature.Length of 0 and an exception for
binSignature.Value.

Can anyone tell me what I've got wrong?
 
When writing image data into DB use:

Dim sigData() as Byte
Dim param as SqlCeParameter = cmd.Parameters.Add("Signature",
SqlDbType.Image, sigData.Length);
param.Value = sigData;


Read like thi:
sigData = selectreader.GetSqlBinary(ImageField).Value;
 
Back
Top