Results 1 to 2 of 2

Thread: resolved- saving imagebox content to SQL Server

  1. #1

    Thread Starter
    Hyperactive Member scuzymoto's Avatar
    Join Date
    Aug 1999
    Location
    Washington State
    Posts
    316

    resolved- saving imagebox content to SQL Server

    I couldn't find much on this forum to show how to do this so once I figured it out I thought someone else might benefit from this code snipet. later...

    Code:
    ' dimension a memory stream to hold contents of imagebox
    Dim myStream As New IO.MemoryStream()
    
    ' load imagebox image into memory stream
    vfCaptured.Image.Save(myStream, Drawing.Imaging.ImageFormat.Jpeg)
    
    ' establish database connection
    Dim cn As New SqlClient.SqlConnection("data source=MYDATASOURCE;initial catalog=MYDATABASE;persist security info=False;user id=sa;workstation id=SHX20476;packet size=4096;password=mypassword")
    
    ' create SQL statement with image parameter
    Dim cmd As New SqlClient.SqlCommand("Insert Into ImageTable Values ('12345',@Picture)", cn)
    
    ' define image parameter content from memory stream
    Dim P As New SqlClient.SqlParameter("@Picture", SqlDbType.Image, myStream.ToArray.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, myStream.ToArray())
    
    ' add parameter
    cmd.Parameters.Add(P)
    
    ' open database and execute command to store image
    cn.Open()
    cmd.ExecuteNonQuery()
    cn.Close()
    SCUZ

  2. #2
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    This is a great post. Thank you.

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