Storing & Retrieving Images in SQL Mobile
- From: "Heather B."<hbaker@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 28 Nov 2005 09:02:43 -0600
I am trying to take a picture from a PDA and then store that picture in SQL
Mobile which I have done, but when I try to retrieve the picture I get an
out of memory error. I'm not sure I'm storing it correctly though, do I
need to do some sort of compression on it first? I'm using VS 2005 and
merge replication. Thanks, below is my code:
'TO STORE THE IMAGE
Dim fs As New FileStream(strDirectory & "\" & strFileName, FileMode.Open,
FileAccess.Read)
Dim img As Byte() = New Byte(fs.Length) {}
Dim prm As New SqlCeParameter
prm.SqlDbType = SqlDbType.Image
prm.Size = img.Length
prm.Value = img
Me._cmd.CommandText = "Update Employee Set EmployeePic=? Where
EmployeeId=1194"
Me._cmd.Parameters.Clear()
Me._cmd.Parameters.Add(prm)
Me._cmd.ExecuteNonQuery()
fs = Nothing
img = Nothing
prm = Nothing
'TO RETRIEVE THE IMAGE, CODE FAILS ON
DIM BMP WITH OUT OF MEMORY
Dim img As Image
Dim sqlce As SqlCeDataReader
sqlce = globals.gDB.GetEmployeePic(1194)
Try
Dim byt As Byte()
While sqlce.Read
byt = sqlce.Item("EmployeePic")
Dim bmp As New Bitmap(New System.IO.MemoryStream(byt))
img = bmp
bmp = Nothing
End While
Me.PictureBox1.Image = img
Catch ex As OutOfMemoryException
MessageBox.Show(ex.Message)
End Try
.
- Follow-Ups:
- Re: Storing & Retrieving Images in SQL Mobile
- From: Alex Feinman [MVP]
- Re: Storing & Retrieving Images in SQL Mobile
- Prev by Date: Re: How to GetDC?
- Next by Date: Re: SQL CE
- Previous by thread: Getting listview doublebuffered and exporting OnPaint method problem
- Next by thread: Re: Storing & Retrieving Images in SQL Mobile
- Index(es):
Relevant Pages
|