Results 1 to 3 of 3

Thread: Images in SQL Table to Imagelist

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Location
    Amsterdam, Holland
    Posts
    36

    Question Images in SQL Table to Imagelist

    Hi All,

    I try to put images from a table in SQL in an Imagelist.
    Please can anybody help me with some code to fix this problem, I stepped over from Delphi to VB.NET and in delphi it was quit simple to do this.

    CODE:

    strSQL = "SELECT image FROM icons"
    cnSQL = New SqlConnection(AssignConnectionString("DB"))
    cnSQL.Open()
    cmSQL = New SqlCommand(strSQL, cnSQL)
    drSQL = cmSQL.ExecuteReader()
    Dim OwnList As New ImageList
    Do While drSQL.Read
    OwnList.Images.Add(drSQL.Item("image").SqlDbType.image)
    ....
    ....
    Loop
    drSQL.Close()
    cnSQL.Close()
    cmSQL.Dispose()
    cnSQL.Dispose()

    Thanks,
    AXH:

  2. #2

    Thread Starter
    Member
    Join Date
    Sep 2003
    Location
    Amsterdam, Holland
    Posts
    36

    Question

    Can somebody give me some help to resolve this problem ?

    Thanks
    AXH

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2003
    Location
    Amsterdam, Holland
    Posts
    36
    Perhaps this code will help somebody
    This is the other way arround


    Dim ms As New MemoryStream
    PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
    Dim arrimage() As Byte = ms.GetBuffer
    ms.Close()

    strSQL = _
    "INSERT INTO icons (image) " & _
    "VALUES (@imag)"
    cnSQL = New SqlConnection AssignConnectionString)
    cmSQL = New SqlCommand(strSQL, cnSQL)
    cmSQL.Parameters.Add("@imag", SqlDbType.Image).Value = arrimage
    cnSQL.Open()
    cmSQL.ExecuteNonQuery()

    This code wil save a picture into the db and it works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width