G
Guest
I am trying to update a field of type IMAGE.
I am able to do this by deleting the record and then INSERTing a new record
as shown below in the commented section.
But I really want to do this with an UPDATE command as shown below in the
un-commented code. I assume this is possible.
The image is passed as a byte array called 'content'. I then want to update
the column STREAM with the new 'CONTENT'.
I don't know the correct SQL syntax for this UPDATE command.
protected static void StoreImage(byte[] content, int iID)
{
OleDbConnection con = ConnectionOledb;
con.Open();
try
{
// update record with image
OleDbCommand update = new OleDbCommand("UPDATE Images SET [Stream] = " +
content + " WHERE ID = " + iID, con);
update.ExecuteNonQuery();
//Long winded way. Delete whole record, then replace
// OleDbCommand delete = new OleDbCommand("DELETE * FROM Images WHERE ID "
+ iID, con);
// delete.ExecuteNonQuery();
//
// OleDbCommand insert = new OleDbCommand("INSERT into Images ([stream],
ID) values (@image, @ID)", con);
// OleDbParameter imageParameter = insert.Parameters.Add("@image",
OleDbType.Binary);
// imageParameter.Value = content;
// imageParameter.Size = content.Length;
// OleDbParameter IDParam = insert.Parameters.Add("@ID", OleDbType.Integer);
// IDParam.Value = iID;
// insert.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
I am able to do this by deleting the record and then INSERTing a new record
as shown below in the commented section.
But I really want to do this with an UPDATE command as shown below in the
un-commented code. I assume this is possible.
The image is passed as a byte array called 'content'. I then want to update
the column STREAM with the new 'CONTENT'.
I don't know the correct SQL syntax for this UPDATE command.
protected static void StoreImage(byte[] content, int iID)
{
OleDbConnection con = ConnectionOledb;
con.Open();
try
{
// update record with image
OleDbCommand update = new OleDbCommand("UPDATE Images SET [Stream] = " +
content + " WHERE ID = " + iID, con);
update.ExecuteNonQuery();
//Long winded way. Delete whole record, then replace
// OleDbCommand delete = new OleDbCommand("DELETE * FROM Images WHERE ID "
+ iID, con);
// delete.ExecuteNonQuery();
//
// OleDbCommand insert = new OleDbCommand("INSERT into Images ([stream],
ID) values (@image, @ID)", con);
// OleDbParameter imageParameter = insert.Parameters.Add("@image",
OleDbType.Binary);
// imageParameter.Value = content;
// imageParameter.Size = content.Length;
// OleDbParameter IDParam = insert.Parameters.Add("@ID", OleDbType.Integer);
// IDParam.Value = iID;
// insert.ExecuteNonQuery();
}
finally
{
con.Close();
}
}