Introduction
If you ever wanted your Pocket PC to show images from your SQL Server database, this is what you want. You don't have to store the pictures on your PPC. Using a Web Service you can now send the picture through the Web Service to your PPC.
Here's the code
First in your Web Service, add this Public
method:
<WebMethod()>
Public Function GetPicture(ByVal RowID As Long) As Byte()
Dim Con As SqlClient.SqlConnection
Dim DA As SqlClient.SqlDataAdapter
Dim SQL As String
Dim BA As Byte()
Dim SC As New SqlCommand
SQL = "SELECT Picture FROM Pictures WHERE RowID = " & RowID
Con = New SqlConnection("User ID=YourID;password=YourPassword;" & _
"Data Source=SQLSERVER;Initial Catalog=DatabaseName")
SC.Connection = Con
SC.Connection.Open()
SC.CommandType = CommandType.Text
SC.CommandText = SQL
BA = CType(SC.ExecuteScalar(), Byte())
SC.Connection.Close()
SC.Dispose()
Return BA
End Function
Make sure it is compiled and the function returns a BLOB
of letters and numbers.
On your Pocket PC (VB.NET), just add a form with a PictureBox
named PictureBox1
and your picture is now there.
Public Sub SetPicBox(ByVal ImageArray As Byte())
Dim ArraySize As New Integer
ArraySize = ImageArray.GetUpperBound(0)
Dim fs As New System.IO.FileStream("tmp.gif",
System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)
fs.Write(ImageArray, 0, ArraySize + 1)
fs.Close()
PictureBox1.Image = New Bitmap("tmp.gif")
End Sub
Private Sub frmPicture_Load(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.Load
SetPicBox(YourService.GetPicture(23))
End Sub