473,326 Members | 2,136 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,326 software developers and data experts.

Uploading Pictures to Database

I work with VS2008 and i will be very thankfull to anyone who can tell me how to create an upload control that uploads pictures directly to a database.

Any help in this regard would be greatly appreciated.

Darina
Aug 23 '08 #1
6 1339
joedeene
583 512MB
im not experienced with databases, but how about reading the bytes, from the file's stream, and then either converting it to a string and then writing it to a database or just writing the bytes to the database, of course you'd need to put some kind of text that lets you know theres another picture bytes. for example, reading it...

Expand|Select|Wrap|Line Numbers
  1.  ' Open a file that is to be loaded into a byte array
  2.         Dim oFile As System.IO.FileInfo
  3.         oFile = New System.IO.FileInfo("byte-data.dat")
  4.  
  5.         Dim oFileStream As System.IO.FileStream = oFile.OpenRead()
  6.         Dim lBytes As Long = oFileStream.Length
  7.  
  8.         Dim fileData(lBytes) As Byte
  9.  
  10.         ' Read the file into a byte array
  11.         oFileStream.Read(fileData, 0, lBytes)
  12.         oFileStream.Close()
so filedata is an array of bytes, you can either write that, or you could use the system.text.encoding.ascii, and do the .getstring method, hope i helped? and set all of this to the event on the button click method you want
Aug 23 '08 #2
Curtis Rutland
3,256 Expert 2GB
Not quite, the Byte needs to be a Byte array. Don't remember how to do arrays in VB.NET off the top of my head.
Aug 23 '08 #3
Thanx but if i knew how to do that i would have probably solved my problem. Any other suggestions?
Aug 24 '08 #4
NitinSawant
270 100+
you can try this
Expand|Select|Wrap|Line Numbers
  1.             SqlConnection connection1 = new SqlConnection(connectionString);
  2.             connection1.Open();
  3.             SqlCommand cmd1 = new SqlCommand(sql1,connection1);
  4.             int i=cmd1.ExecuteNonQuery();
  5.             if (txtFileName.Text != "")
  6.             {
  7.                 FileStream file = new FileStream(curFileName, FileMode.OpenOrCreate, FileAccess.Read);
  8.                 byte[] rawdata = new byte[file.Length];//buffer
  9.                 //MessageBox.Show("File length: " + file.Length.ToString()+"bytes");
  10.                 file.Read(rawdata, 0, Convert.ToInt32(file.Length));//reads the data and writes to buffer
  11.                 file.Close();
  12.                 <code removed by moderator>
  13.              }
  14.  
modify the code according to ur table names!!
Aug 24 '08 #5
Curtis Rutland
3,256 Expert 2GB
Nitin646, as a full member you should know better than to provide fully coded solutions that members can copy and paste. We're here to help, not to do all the work for people. I've removed the part of code where you upload to a database.

MODERATOR
Aug 24 '08 #6
Curtis Rutland
3,256 Expert 2GB
OK, therina, you've got some code to get you started, even though it is in C#. I had to remove some of it, because of the rules of this site.

So, this code is the second step. What you need to do is use the fileupload control built into ASP.NET, and save the file to a temp location. Then use the posted code (translated to VB.NET, of course) to get a Byte array. Then, you will need to do your insert statement. You need to use a parametrized query. You can see an example of this type of query in this article:
http://bytes.com/forum/thread635615.html
One of the parameters needs to be your Byte array. The database type for this varies. In SQL Server, it is Image. In other dbs, it can be BLOB. But they behave the same.

I hope this helps.
Aug 24 '08 #7

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

Similar topics

2
by: Sirano | last post by:
Hello, I'll want automatic upload pictures from a specified folder to the internet with PHP code. Or does somebody know a Website where I could find an answer for this. Thanks, Sirano
5
by: xool | last post by:
Hi all Can anyone tell me the simplest easiest way to upload pictures to a directory. It's for a content management page - text boxes for new record information and a file browse form box for...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
3
by: Carlos | last post by:
Hello Forum, I would appreciate it if you could recommend settings to use auto-vacuum in my version 7.4 database. I am uploading several thousands records in the database at a rate of ~1 second...
0
by: foolygoofy26 | last post by:
I'm trying to make a form or perhaps simply use Web Developer 2005 or SQL Server 2005 management to populate a database with pictures. So simply I want upload images to an sql database, if I make a...
2
by: C.Joseph Drayton | last post by:
Hi All, I have a web site I am developing, and have a question. I would like members to be able to upload pictures. Do you think they should be saved as individual files or should they be put...
9
by: C.Joseph Drayton | last post by:
Hi All, I have a web site I am developing, and have a question. I would like members to be able to upload pictures. Do you think they should be saved as individual files or should they be put...
0
by: lyealain | last post by:
hi guys.. i have spent up my time looking and understanding the sample code from everywhere for uploading picture into mysql database by using asp script.. but i found it very hard to understand......
1
by: onye52000 | last post by:
Hi. I want to be able to change the text and pictures of a flash movie from a control panel on the same running flash movie. I will need to upload pictures on the movie with the necessary text...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.