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("U PDATE Images SET [Stream] = " +
content + " WHERE ID = " + iID, con);
update.ExecuteN onQuery();
//Long winded way. Delete whole record, then replace
// OleDbCommand delete = new OleDbCommand("D ELETE * FROM Images WHERE ID "
+ iID, con);
// delete.ExecuteN onQuery();
//
// OleDbCommand insert = new OleDbCommand("I NSERT into Images ([stream],
ID) values (@image, @ID)", con);
// OleDbParameter imageParameter = insert.Paramete rs.Add("@image" ,
OleDbType.Binar y);
// imageParameter. Value = content;
// imageParameter. Size = content.Length;
// OleDbParameter IDParam = insert.Paramete rs.Add("@ID", OleDbType.Integ er);
// IDParam.Value = iID;
// insert.ExecuteN onQuery();
}
finally
{
con.Close();
}
}
--
Tinius 2 21360
Hi,
You should be using parameters for the update, in the same way you are
doing it for the insert
OleDbCommand update = new OleDbCommand("U PDATE Images SET [Stream] = @image
WHERE ID = " + iID, con);
OleDbParameter imageParameter = insert.Paramete rs.Add("@image" ,
OleDbType.Binar y);
imageParameter. Value = content;
imageParameter. Size = content.Length;
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Tinius" <Ti****@discuss ions.microsoft. com> wrote in message
news:9F******** *************** ***********@mic rosoft.com... 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("U PDATE Images SET [Stream] = " + content + " WHERE ID = " + iID, con); update.ExecuteN onQuery();
//Long winded way. Delete whole record, then replace // OleDbCommand delete = new OleDbCommand("D ELETE * FROM Images WHERE ID " + iID, con); // delete.ExecuteN onQuery(); // // OleDbCommand insert = new OleDbCommand("I NSERT into Images ([stream], ID) values (@image, @ID)", con); // OleDbParameter imageParameter = insert.Paramete rs.Add("@image" , OleDbType.Binar y); // imageParameter. Value = content; // imageParameter. Size = content.Length; // OleDbParameter IDParam = insert.Paramete rs.Add("@ID", OleDbType.Integ er); // IDParam.Value = iID; // insert.ExecuteN onQuery(); } finally { con.Close(); } } -- Tinius
Hi Ignacio
Perfect
Thanks
Tinius
"Ignacio Machin ( .NET/ C# MVP )" wrote: Hi,
You should be using parameters for the update, in the same way you are doing it for the insert
OleDbCommand update = new OleDbCommand("U PDATE Images SET [Stream] = @image WHERE ID = " + iID, con);
OleDbParameter imageParameter = insert.Paramete rs.Add("@image" , OleDbType.Binar y); imageParameter. Value = content; imageParameter. Size = content.Length;
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: oldandgrey |
last post by:
I'm looking at producing an application that will allow multiple users to
order multiple items/ parts from what would effectively be an online store.
These users could be ordering several hundred items/ parts at a time, each
item/ part ordered representing one box or several hundred.
Each part record will require the "total stock" to be down dated and each
unit will require updated to show it as having been picked (plus other
info).
|
by: RDRaider |
last post by:
How can I update only the date portion of a datetime field?
Example:
datetime field = '3/12/1995 12:05:50 PM'
How can I change just the day '12' to a '7'
Thanks
|
by: James P. |
last post by:
Hello there,
I have a bound-form using Navigator so that the user can move back and
forth to update record in the form. Every time a record was modified
and the user clicks the Navigator to either move backward or forward
to the next record, a message is popped up asking the user to confirm
the change. If the user clicks "Yes", the record should be updated
and the Navigator takes the user to the next record as clicked. If
the user...
|
by: Daniel |
last post by:
Does someone know how to update record in ASP.NET ?
Because i face a problem after updating the record in SQLServer database.
The problem is :
I do update to a record's field called DateIn.
After updating the whole DateIn column field will also same value as the updated value ?
Does any one know why ??
Your help will be appreciated.
Daniel.
|
by: Matt |
last post by:
I'm having difficulty with trying to update a Access memo field through an
SQL statement where the value I'm trying to pass is longer than 255
characters. The field is being truncated. I'm using a simple INSERT INTO
sql command. Anyone know a way around this?
Sample
strSQL = "INSERT INTO tblListings " & _
"(Dir, Street, City, State, " & _
"AFirst, Price, ALast, MainPhoto, Summary, Details,
| |
by: Sukhanov Volodya |
last post by:
Hello, all!
Does anybody knows, how I can show an image field SQL Server using VB. NET ?
I have an database, which has an table with an field which has type 'image'
(the type of field)
I want to save an picture in this field, and then show this picture by an
datagrid or other control.... (for each record desirable)
Does anybody knows how to do it ?
Volodya Sukhanov
|
by: Laurahn |
last post by:
How can i send from VB 2005 a null value to a image field on a database in
SQL 2005
|
by: dodgeyb |
last post by:
Hi there,
Trying to allow client to upload image, thumbnail it, and save it into
sql table image field.
Code compiles & runs but image cannot be retrieved. any clues what I'm
doing wrong pls !
Dim origImage As System.Drawing.Image =
System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
|
by: Microblitz |
last post by:
Hi All,
I started messing about with VBA yesterday (I'm a newbie at this language) and have run across a problem which i hope you can help me with.
I'm writing a little stock control program in clicking a command button opens a message box which asks for a number of items to add to the currently displayed record in the main form (called Parts).
You's think this would be simple and i have some code which i have cobbled together which I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |