Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 6th, 2006, 02:33 PM
Authorized User
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default Passing Image File as a parameter

Hello Professionals of this forum!
I need to code a program for a server client employee record application in windows with C#. I need to learn first, how can I fill a control like a picture box on the windows form from a picture file saved on de PC, and second, how can I initialize some type of variable in code to pass that same picture as a parameter to the stored procedure that inserts each record for the employees table in my DB? Please help is greatly appreciated and needed, I'm new to C#, I'm learning, but my boss want's me to fullfil this task with no excuses. Thanks a lot in advance!


MAKO - "El super simio"
MAKO - \"El super simio\"
Old October 7th, 2006, 04:04 AM
Friend of Wrox
Join Date: May 2006
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts

Use System.Drowing.Image.
To store image in db declare field type as image->>

Old October 10th, 2006, 12:24 PM
Authorized User
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO

Thanks for your reply Bijgupt, it is a guiding light. However I'm still not quite clear of how can I initialize the image variable with the picture file stored in the disc. I thought of an open file dialog for the user to search for the file, but then I get confused with how to do the rest to initialize the image variable. A little bittie more help, please! Thank you!

MAKO - "El super simio"
Old October 10th, 2006, 12:55 PM
Wrox Author
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

What you can do is, for example, place a picture box on your form with a default image then use your File Dialog and have the user select an image file. Now here is the question I have, after the use selects the image from the file dialog does that image need to be automatically placed in the picture box?

Or, after the user selects a file, do they hit submit of some sort to write the image to a database THEN the picture box has an image associated with it?

If you look at the code for your form and, assume that you have added an image to the picturebox your code will look something like:

this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictu re.ext")));

All its doing is casting the object to a type of System.Drawing.Image.

If, for example, you were to stream this file to disk as opposed to saving it to the database you could do something like this in code:

pictureBox1.Image = Image.FromFile("pic.jpg")

However, since you need to place this into a database you are going to have to write some GDI functionality that will pull the byte stream from SQL and then create an image object on the fly. (Depending on your skill set, GDI can be a bit of a challenge, but for what you need to do, it is relatively simplistic)

For example:
Bitmap bmpFile;
MemoryStream stmFile = new MemoryStream();
BinaryWriter objWriter = new BinaryWriter(stmFile);
bmpFile = new Bitmap(stmFile);

I assume you pull back the data into a datatable and that the data sits at Row 0 Position 0

From there all you have to do is add it to your picture box.


--Stole this from a moderator

I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing MXML file as XML Parameter maulik33 Flex 0 January 9th, 2008 12:49 PM
passing parameter to xsl file anandjun XSLT 3 March 24th, 2006 02:46 PM
passing an image file to a .net file. sanjeet .NET Web Services 2 September 22nd, 2005 01:26 PM
passing parameter.. suzila VB.NET 2002/2003 Basics 7 May 17th, 2004 08:28 PM
Passing Parameter tgopal Javascript 3 August 7th, 2003 07:54 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.