473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Another Q Regarding a Picture BOX, Savind to Access DB

Sl1ver
196 New Member
hi there
here's my code, it get and displays the image for a preview but i can't save it to my access DB i really need help with this one
Expand|Select|Wrap|Line Numbers
  1.  public void openBMP(String filename)
  2.         {
  3.             //Declare the OpenFileDialog as a new OpenFileDialog.
  4.             OpenFileDialog openFileDialog = new OpenFileDialog();
  5.             //Declare the PictureBox as a new PictureBox
  6.             //PictureBox pic = new PictureBox();
  7.             //Set the openFileDialog's Filter.
  8.             openFileDialog.Filter = "Bitmap Image|*.bmp|All Files|*.*";
  9.             //Set the openFileDialog's FileName to nothing.
  10.             openFileDialog.FileName = "";
  11.             string path = "";
  12.             //Show the openFileDialog
  13.             if (openFileDialog.ShowDialog(this) == DialogResult.OK)
  14.             {
  15.                 //To do code if the Open button was pressed
  16.                 //Use something like:
  17.                 filename = openFileDialog.FileName;
  18.                 pic.Image = Image.FromFile(filename);
  19.                 pic.Size = new System.Drawing.Size(280, 140);
  20.                 pic.SizeMode = PictureBoxSizeMode.CenterImage;
  21.                 path = System.IO.Path.GetDirectoryName(openFileDialog.FileName);
  22.                 txtComp_Image.Text = path;
  23.             }
  24.             else
  25.             {
  26.                 return;
  27.             }
  28.  
May 7 '09 #1
7 2249
tlhintoq
3,525 Recognized Expert Specialist
here's my code, it get and displays the image for a preview but i can't save it to my access DB
You've shown us the code you state already works (open/preview image)... but none of the code that you are having problems with (save to Access db). Please show us what you are trying along with the error(s) you are getting from your save routine.
May 7 '09 #2
Sl1ver
196 New Member
Problem is i dont know how to convert it so that it will get inserted into the DB as OLE object. The other text boxes and everything inserts fine. i just would like to know how to convert the image.
May 8 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
Maybe covert to/from a byte array?
Since I don't deal with databases I've never had to deal with this issue.
Anyone else?
May 8 '09 #4
PRR
750 Recognized Expert Contributor
1. Read the image as byte[].. FileStream
2. Use Sqlparameter of type image... Value as byte[]...Look into SqlDbType.Image
May 11 '09 #5
balame2004
142 New Member
Try this code sample to insert image into database table.

Expand|Select|Wrap|Line Numbers
  1. System.IO.MemoryStream ms = new System.IO.MemoryStream();
  2.             Image img = Image.FromFile(@"C:\Documents and Settings\balaji.umapathi\Desktop\Arrow.PNG");
  3.             img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  4.             System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
  5.             cmd.CommandText = "INSERT INTO ImageDataTable(ImageName,ImageData) VALUES('Arrow.PNG',@Image)";
  6.             System.Data.SqlClient.SqlParameter param = new System.Data.SqlClient.SqlParameter("@Image",SqlDbType.Image);            
  7.             param.Value = ms.GetBuffer();
  8.             cmd.Parameters.Add(param);
  9.             cmd.ExecuteNonQuery();
May 11 '09 #6
Sl1ver
196 New Member
The problem is that i dont know to save the picturebox image as OLE Object in an access database
May 11 '09 #7
PRR
750 Recognized Expert Contributor
You need to save the image not the picturebox...
May 11 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ulrike | last post by:
I need to bind in (thumbnail-sized) pictures into an Access Database in such a way that there is one picture for each record (abt. 3000 records on the whole). Ideally, the pictures should show on...
1
by: ANSWER | last post by:
Hi, I have Employee database in MS Access. Now I want to include picture of employees near personal contacts. 1/ How can I do that 2/ Where am I going to save them. Thanks
1
by: kumarmanoj_pat | last post by:
hi, i am trying to insert a picture in my database through SQL. i have already tried but could not get success. if any one know about this then please helpnme.
20
by: hufaunder | last post by:
I have 16-bit data that I want to display. In order to display it I compress a certain range of the input data into 8 bit (I need control over this). All seems to work ok except that it is dead...
2
by: alpana yadav | last post by:
hello everybody i want to know how to save picture in access through vb.net and after saving we have to delete the picture from hard disk and then read picture from database(access) thanks...
3
by: amanda27 | last post by:
Hi there I have an Access 2003 report that has different information for different projects my department is working on. It gives the status of the projects weekly. For each project they have a...
2
by: kentgorrell | last post by:
I had a wonderful time working out how to read and write BLOBs using GetChunk until I found the new streaming object in ADO 2.6 very easy. Now I am confronted with DIBs The code I have is VB6 but...
1
by: Franzi | last post by:
Hello, I have got a question concerning putting pictures in access records. I have a moviecatalogue in access and want to put individual dvd covers to each record... I figured out how to put a...
1
by: MaryKJolly | last post by:
I am using visual basic 6. I need the code for loading & saving photo to access database (data type of the field has been set as OLEObject)through picture/image box in a form and to display the...
0
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.