Saving an image in Sql Ce

G

Guest

Hello, I am trying to save a byte array to my sql ce database using a
SqlCeDataAdapter and a DataTable. Here is my code, after I run it the Notes
field(my image field) is still NULL.

SqlCeDatabase db = SqlCeDatabase.Instance;
db.OpenDatabase(MAT_Common.DatabasePath);

//SAVE NOTES IMAGE
DataTable dt = new DataTable();
strSQL = @"Select SignRequestID, Notes From SignRequest Where SignRequestID
= '{" + ID + "}'";

SqlCeDataAdapter da = new SqlCeDataAdapter(strSQL, db.Conn);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);

da.InsertCommand = cb.GetInsertCommand();
da.DeleteCommand = cb.GetDeleteCommand();
da.UpdateCommand = cb.GetUpdateCommand();

da.Fill(dt);

dt.Rows[0].BeginEdit();
dt.Rows[0].ItemArray = new object[] {ID, pic.GetSignature()}; //
GetSignature returns a byte[]
dt.Rows[0].EndEdit();
dt.AcceptChanges();
da.Update(dt);

db.CloseDatabase();

Thanks for any help,
Lindsay
 
A

Alex Feinman [MVP]

Get rid of AcceptChanges. That clears "Modified" flag on the row and Update
ignores it.
 
G

Guest

Thanks so much!

Alex Feinman said:
Get rid of AcceptChanges. That clears "Modified" flag on the row and Update
ignores it.

Lindsay said:
Hello, I am trying to save a byte array to my sql ce database using a
SqlCeDataAdapter and a DataTable. Here is my code, after I run it the
Notes
field(my image field) is still NULL.

SqlCeDatabase db = SqlCeDatabase.Instance;
db.OpenDatabase(MAT_Common.DatabasePath);

//SAVE NOTES IMAGE
DataTable dt = new DataTable();
strSQL = @"Select SignRequestID, Notes From SignRequest Where
SignRequestID
= '{" + ID + "}'";

SqlCeDataAdapter da = new SqlCeDataAdapter(strSQL, db.Conn);
SqlCeCommandBuilder cb = new SqlCeCommandBuilder(da);

da.InsertCommand = cb.GetInsertCommand();
da.DeleteCommand = cb.GetDeleteCommand();
da.UpdateCommand = cb.GetUpdateCommand();

da.Fill(dt);

dt.Rows[0].BeginEdit();
dt.Rows[0].ItemArray = new object[] {ID, pic.GetSignature()}; //
GetSignature returns a byte[]
dt.Rows[0].EndEdit();
dt.AcceptChanges();
da.Update(dt);

db.CloseDatabase();

Thanks for any help,
Lindsay
 
Top