ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Microsoft-Related >> VB.NET
 
 
 
Question
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
 Question Submitted By :: Rahulrathod
I also faced this Question!!     Rank Answer Posted By  
 
Answer
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
 
0
Debolina
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com