how to store photos in sql server and...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaryan
    New Member
    • Nov 2006
    • 82

    #1

    how to store photos in sql server and...

    hi all,
    i just want to know how to store photos in sql server 2000 and to retrieve it thro' vb
  • pavanpareta
    New Member
    • Jun 2006
    • 11

    #2
    Try this Code:.........

    Code:
            Dim ms As New MemoryStream
            Me.PictureBox1.Image.Save(ms, Me.PictureBox1.Image.RawFormat)
    
            Dim arrayImage() As Byte = ms.GetBuffer
            ms.Close() ' Closes the Memory Stream
    
            Dim nStr As String = Me.Label1.Text.Substring(Me.Label1.Text.LastIndexOf("\") + 1)
    
            Dim strQuery As String = "INSERT INTO Pic(Name, Picture) VALUES(@Name, @Picture)"
    
            Dim objcommand As New SqlCommand(strQuery, Me.SqlConnection1)
            With objcommand
                .Parameters.Add(New SqlParameter("@Name", SqlDbType.NVarChar, 50)).Value = nStr
                .Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrayImage
            End With
    
            Me.SqlConnection1.Open()
            objcommand.ExecuteNonQuery()
            MessageBox.Show("Image Saved Into the DataBase")
            Me.SqlConnection1.Close()

    Comment

    • aaryan
      New Member
      • Nov 2006
      • 82

      #3
      hi,
      thankz for your prompt reply. i will try it and report you abt that.

      Comment

      Working...