473,378 Members | 1,360 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,378 software developers and data experts.

Upload Image to SQL

Is there any good example on how to do this, better if it shows how to limit
the image to X size and save both..original and thumbnail size to SQL.

TIA
Nov 21 '05 #1
1 1126

Hi,

I do it like this:
Import System.Data.SqlClient
Import System.IO
....
.....
.....

dim strFileName = ....
dim myFile as System.IO.FileInfo
dim bw as BinaryWriter
dim br as BinaryReader
dim lngFileSize as long
dim arybyteFileData() as Byte
dim strFileName as string

dim mda as new SQLClient.SqlDataAdapter
dim cmdInsert as new SqlClient.SqlCommand

dim strReadFromFile as string = txtFileName.Text // file name entered
in text box
If File.Exists(strFileName) Then
Dim anImage() as Byte = GetImage(strFileName) // se below

myFile = new System.IO.FileInfo(fileName:=strReadFromFile)
lngFileSize = myFile.Length
strFileName = myFile.Name

Redim arybyteFileData(lngFileSize)

strSQL = "INSERT INTO myTable ( .... ) VALUES( @parID,
@parDateAdded, @parImage, @parFileName)

cmdInsert.CommandText = strSQL
cmdInsert.Parameters.Add("@parID", SQLDbTyhpe.BigInt, 8).Value =
lngDocID // if you add image data to another table and actual bytes
in this table (myTable), then you have the id of that image already
cmdInsert.Parameters.Add("@parDateAdded", SQlDbType.DateTime).value
= ...
cmdInsert.Parametes.Add("@parImage", SqlDbType.Image,
anImage.Length).Value = anImage
mda.InsertCommand = cmdInsert
mda.InsertCommand.ExecuteNonQuery()
end if
public Function GetImage(ByVal strFilePath as string) as Byte()
Dim fs as FileStream = new FileStream(strFilePath, FileMode.Open,
FileAccess.Read)
dim br as BinaryWriter = new BinaryWriter(fs.Length)
dim theImage() as Byte = br.ReadBytes(fs.Length)

br.close()
fs.Close()

retrun theImage
end function
HTH
Dino

On Mon, 21 Feb 2005 11:35:38 -0600, "C CORDON" <tc******@hotmail.com>
wrote:
Is there any good example on how to do this, better if it shows how to limit
the image to X size and save both..original and thumbnail size to SQL.

TIA


Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: SEMIH DEMIR | last post by:
Sitelerden birinde verilen yabancı kaynakli bir scriptti duzenledim yanlız birseyin içinden bir turlu cıkamadım işin aslı ilk defa persistin upload componentini kullanacam yanlız suanki haliyle...
4
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
3
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
1
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
7
by: xx75vulcan | last post by:
Hi, I've got a PHP Upload Form that works great, unless that is, the image your uploading has been modified through a photo editing software. Example: if I upload the image straight from a...
7
by: mishrarajesh44 | last post by:
hii all Truly telling i hav got this code from net & i am finding error while running the code below.. code:- <?php $idir = "photo/"; // Path To Images Directory $tdir =...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.