H
Heather B.
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
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