Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to store jpeg / gif / bmp image in database and how to
retrieve them? The most stressful condition is database is
distributed and stored images can be retrive from any
computer in network and any one can store images from other
computer!! plss help its urgent.......RAHUL RATHOD

Answers were Sorted based on User's Feedback



How to store jpeg / gif / bmp image in database and how to retrieve them? The most stressful condit..

Answer / debolina

For Save Images:

Private Sub Save()
Dim strConn, strQuery As String
Dim cmd As SqlCommand
Dim img As Image
Dim imagedata As Byte()
Dim imgFormat As Imaging.ImageFormat
Dim myParameter As SqlParameter
Try
img = Image.FromFile(Me.txtImage.Text)
imgFormat = img.RawFormat

imagedata = ConvertImageToByteArray(img, imgFormat)

strQuery = "Insert into TBL_STUDENT
(STUD_NAME,SUBJECT,NUMBER,IMAGES) values ('" & txtName.Text
& "','" & txtSubject.Text & "'," & txtNumber.Text & ",@Image)"
strConn = //Your Connection String
conn = New SqlConnection(strConn)
cmd = New SqlCommand(strQuery, conn)

myParameter = New SqlParameter("@Image",
SqlDbType.Image, imagedata.Length)
myParameter.Value = imagedata
cmd.Parameters.Add(myParameter)


conn.Open()
cmd.ExecuteNonQuery()

MsgBox("Saved Successfully", MsgBoxStyle.OkOnly)
Catch ex As Exception

End Try
End Sub

Private Shared Function ConvertImageToByteArray(ByVal
imageToConvert As System.Drawing.Image, ByVal formatOfImage
As Imaging.ImageFormat) As Byte()
Dim Ret As Byte()

Try
Using ms As New MemoryStream()
imageToConvert.Save(ms, formatOfImage)
Ret = ms.ToArray()
End Using
Catch generatedExceptionName As Exception
Throw
End Try

Return Ret
End Function

For Retrieve:

Private Sub RetrieveImages()
Dim strConn As String
Dim cmd As SqlCommand
Dim da As SqlDataAdapter

Try
strConn = //Connection string
conn = New SqlConnection(strConn)
cmd = New SqlCommand("Select * from
TBL_STUDENT", conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds)
Catch ex As Exception

End Try
End Sub

Is This Answer Correct ?    4 Yes 1 No

How to store jpeg / gif / bmp image in database and how to retrieve them? The most stressful condit..

Answer / raj

Hi Rahul,
if you want to save image in SQL Server DataBase,
first we have to convert that image into bytes(BCoz SQL
Server support byte format).
using system.io.iostream we can convert image into stream
of bytes.

For example :

stfFilename is path that contain your image.

Public Shared Function LoadImage(ByVal stfFilename As
String) As System.Drawing.Image

Dim oStream As System.IO.Stream
Dim oAssembly As System.Reflection.Assembly
oAssembly = System.Reflection.Assembly.GetEntryAssembly
oStream = oAssembly.GetManifestResourceStream(stfFilename)
Return System.Drawing.Image.FromStream(oStream)
End Function

for retrieving image from DB just reverse concept.

Is This Answer Correct ?    4 Yes 2 No

How to store jpeg / gif / bmp image in database and how to retrieve them? The most stressful condit..

Answer / surabhi

i also need this codding the coding written aboye is not
working plzzz help me

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More VB.NET Interview Questions

What is the difference between value and reference types?

0 Answers  


what is the root namespace for all types?

8 Answers  


What is the difference between .dll extension and .exe extension files?

0 Answers  


what do you mean by .Net Framework

17 Answers   Assurgent, College School Exams Tests, Guru Tech, Krishna Infotech, Ksb, Microsoft,


What is intermediate language in .NET ?

20 Answers   Digital GlobalSoft,


Explain the components of common language runtime.

0 Answers  


hello friends, I have created a animated button in VB.NET. As its dll file coding can be viewed and also copied to some other location. So my question is how can I protect the Dll file of the animated button so that noone can access it. Any idea about this???????? Thanks Rekha

3 Answers  


sql satement for 2nd maximum value

15 Answers   NIIT,


hi dear ? MY problem is that i m developing software for Library. and i want to connect a third party software with my VB.net program in order to calculate DDC number.I dont know how to do this if any body can help me please?

1 Answers  


How to create Crystal Report in vb.net with coding

1 Answers   A3Logics, Ascent, TCS,


Trace and Debug belongs to which namespaces?

5 Answers  


Define manifest?

0 Answers  


Categories