Click to See Complete Forum and Search --> : Retrieve image from SQL Server Database
dovobet
March 9th, 2010, 04:53 PM
Hello all
I want to read the byte data I have stored in a database which represents an image. I then want to apply this image as the picture of a Contact in Outlook. I am trying to use the getBytes() method but I am unsure of how to do this.
I have the code below so far.
'folder' is a custom folder I have created in Outlook separately. It stores the contacts.
Outlook.ContactItem newContact =
(Outlook.ContactItem)folder.Items.Add
(Outlook.OlItemType.olContactItem);
newContact.Attachments = reader.GetBytes(<some parameters to be added>);
any help is much appreciated
rliq
March 9th, 2010, 11:16 PM
You have used an instance of an object called 'reader', but you do not state what class that object is...?
Also your code seems to have nothing to do with the title of the thread?
Have you gotten the image from the SQL database or is it that bit you are having problems with? If you are, can you show us that bit of code please.
Can you put your code inside code tags please.
dovobet
March 10th, 2010, 06:50 PM
You have used an instance of an object called 'reader', but you do not state what class that object is...?
Also your code seems to have nothing to do with the title of the thread?
Have you gotten the image from the SQL database or is it that bit you are having problems with? If you are, can you show us that bit of code please.
Can you put your code inside code tags please.
Sorry the code I put was an old version that does not work...
What I wish to do is retrieve an image i have stored in a SQL Server database and then save it.
I have read the file into the database into an Image field with the fieldtype set to "Image". Upon entering the image the field reads <binary data>, showing that something is there.
How do I get images back from a database?
rliq
March 10th, 2010, 09:39 PM
In VStudio within Server Explorer, create a DataConnection to your database.
In VStudio within Solution Explorer Add a Dataset.
Expand you DataConnection and drag the table onto your Dataset's design surface.
I assume your table has an Image type column in it containing your image.
Then look up an example of how to read a row from and SQL database into your Dataset/Table (sorry I'm not in a position to write one right now). Then use:
File.WriteAllBytes(/* filename */, /* data */);
Where the data is the Byte[] field from the DataTable in the Dataset.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.