473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Storing of image in DB using open file dialog box

I want to store an image from PC to ms sql db , I want the details of the coding from the first step. From getting the image to converting to bytes and then storing, Can anyone please provide me the coding part of it..
Feb 9 '12 #1

✓ answered by Newface

RAJASEKAR S,I too came across this issue and got it resolved in the following way
1.datatype of the image column-image
2.in aspx.cs page
HttpPostedFile uploadedImage=null;
byte[] imageData=null;
if (cmdBrowsePhoto.PostedFile != null)
{
imageData = new byte[cmdBrowsePhoto.PostedFile.ContentLength];
uploadedImage = cmdBrowsePhoto.PostedFile;
uploadedImage.InputStream.Read(imageData, 0, (int)cmdBrowsePhoto.PostedFile.ContentLength);
}
and in parameter:
cmd.Parameters.Add(new SqlParameter("@photo", imageData));
Please do let me know if it is workin for you or not!

5 2453
PsychoCoder
465 Expert Mod 256MB
While I personally don't like the practice of storing actual images in the database (way too much overhead, and if SQL goes down then you cannot display your images) but that's your decision.

Given that I think this may help
Feb 9 '12 #2
Hi , thanks. But can i get the c # coding..
And also If storing in Db is overload , Then which is the best way to do it.
Feb 9 '12 #3
PsychoCoder
465 Expert Mod 256MB
First, I'm not going to convert the code to C# for you, you will learn nothing.

Best way, if this is an ASP.NET application then store the images in a folder and the path to the image in your database.
Feb 9 '12 #4
K sir, Thanks for your reply, I ll learn the C # coding part on my own. Thanks a lot.
Feb 9 '12 #5
Newface
16
RAJASEKAR S,I too came across this issue and got it resolved in the following way
1.datatype of the image column-image
2.in aspx.cs page
HttpPostedFile uploadedImage=null;
byte[] imageData=null;
if (cmdBrowsePhoto.PostedFile != null)
{
imageData = new byte[cmdBrowsePhoto.PostedFile.ContentLength];
uploadedImage = cmdBrowsePhoto.PostedFile;
uploadedImage.InputStream.Read(imageData, 0, (int)cmdBrowsePhoto.PostedFile.ContentLength);
}
and in parameter:
cmd.Parameters.Add(new SqlParameter("@photo", imageData));
Please do let me know if it is workin for you or not!
Feb 10 '12 #6

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

Similar topics

1
by: Bernavich2004 | last post by:
Ok I am going nuts. This problem ONLY happens when I use a Microsoft Office 2003 product like word, or .NET development IDE. WHen I use the Open file dialog and click on a folder to drill down,...
1
by: N. Graves | last post by:
Help me please? I'm have users import tables from other Access Database in one of the process needed to use my ADB. To do this the user opens a form with a field for the file directory and...
0
by: ungvichian | last post by:
I am trying to write a program in VC++.Net that will read a text file with wireframe data in it and display the wireframe it represents. This link has a sample of the code I'm basing my program off...
2
by: nissiml | last post by:
hi, i'm trying to open a asp.net web page that list files from a Windows application like winword and select a file from it . what do i have to do to make it happen, is it simple ? Thanks in...
9
by: Amit D.Shinde | last post by:
How to enable user for selecting only folders and not the files with the Open File Dialog. i.e. I want only path of the selected folder is to be returned by Open File Dialog. i.e Open File Dialog...
0
by: Me | last post by:
I have an application that has a text box. At the end on the text box is the standard elypsis (command button) for launching the Open File Dialog box. I want the user to select a certain executable...
3
by: The ants are driving me crazy | last post by:
The open file dialog control in Windows forms has an "Open" button. Is there a way to change the text of the button to something other than "Open"?
2
by: Mattbooty | last post by:
Hello, Not sure if anyone else has seen this bug, but I have a form where the entire form is covered with a picturebox. The picturebox has a mouseup event. I also have an open file dialog for...
1
by: klaydze | last post by:
hi, i don't know how to start my code in uploading an image using open file dialog control. any one who can help me? i want to view the picture that i want to upload using open file dialog and show...
3
by: motogirl | last post by:
I don t knw if im in the right place but please i need help u need to make an open file dialog so that the user can browse an image then i have to save the image. I already did the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
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...

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.