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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the ruby interface generator?

979


What is early binding?

890


Explain manifest?

881


Observations between vb.net and vc#.net?

998


Name the class which allows an element to be accessed using unique key?

952


What is datatype conversion?

1044


Explain the difference between import system.data.sqlclient and system.data.oledb?

952


Why is the xml infoset specification different from the xml dom?

873


What is the use of assembly?

936


How does vb.net achieve polymorphism?

889


Name a feature which is common to all .net languages?

952


What is the purpose of objects present in asp.net?

982


What would you do to remove microsoft visual basic name space?

891


What is the feature anonymous type?

864


Name the tool which can convert visual basic old version to .net compatibility version?

975