Click here to Skip to main content
15,885,141 members
Articles / Programming Languages / Visual Basic

Pocket PC: Get image from Web Service using VB.NET

Rate me:
Please Sign up or sign in to vote.
3.07/5 (9 votes)
20 Apr 2005CPOL 105.4K   30   29
Allows a Web Service to send a picture from SQL Server to the Pocket PC.

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:

VB
<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.

VB
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)
    ' don't ask me why, but I had to add 1 here for this to work
    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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionHow use it in emulator? Pin
Carlo Ingrassia11-Feb-10 23:39
Carlo Ingrassia11-Feb-10 23:39 
AnswerRe: How use it in emulator? Pin
VbGuru61312-Feb-10 2:29
VbGuru61312-Feb-10 2:29 
Generalnice work&#65281;ask for help Pin
hyzfujian31-May-06 15:30
hyzfujian31-May-06 15:30 
GeneralRe: nice work&#65281;ask for help Pin
VbGuru6139-Aug-06 8:21
VbGuru6139-Aug-06 8:21 
GeneralThe same without temporary file Pin
Daniel Dusinski (www.dusinski.prv.pl)5-Mar-06 4:55
Daniel Dusinski (www.dusinski.prv.pl)5-Mar-06 4:55 
Instead of creating temporary file you could just show it directly:

// C# style, .NET CF 2.0
MemoryStream ms = new MemoryStream( ImageArray );<br />
PictureBox1.Image = new Bitmap(ms);<br />
ms.Close();

GeneralRe: The same without temporary file Pin
VbGuru6139-Aug-06 8:20
VbGuru6139-Aug-06 8:20 
Questionwhere to put the image file? Pin
tudou6-Jul-05 17:40
tudou6-Jul-05 17:40 
AnswerRe: where to put the image file? Pin
VbGuru6136-Jul-05 17:49
VbGuru6136-Jul-05 17:49 
QuestionHow to make a copy of my database in a Pocket-pc platform Pin
claudiojose22-Apr-05 8:11
claudiojose22-Apr-05 8:11 
AnswerRe: How to make a copy of my database in a Pocket-pc platform Pin
VbGuru61331-May-05 6:23
VbGuru61331-May-05 6:23 
GeneralLine of code missing Pin
jasonshortt20-Apr-05 9:23
jasonshortt20-Apr-05 9:23 
GeneralRe: Line of code missing Pin
VbGuru61320-Apr-05 9:27
VbGuru61320-Apr-05 9:27 
GeneralRe: Line of code missing Pin
jasonshortt20-Apr-05 9:38
jasonshortt20-Apr-05 9:38 
GeneralRe: Line of code missing Pin
VbGuru61320-Apr-05 9:41
VbGuru61320-Apr-05 9:41 
GeneralRe: Line of code missing Pin
NSieger21-Apr-05 6:22
NSieger21-Apr-05 6:22 
GeneralRe: Line of code missing Pin
VbGuru61321-Apr-05 6:32
VbGuru61321-Apr-05 6:32 
GeneralRe: Line of code missing Pin
cehrnow26-Apr-05 5:54
susscehrnow26-Apr-05 5:54 
GeneralRe: Line of code missing Pin
cehrnow26-Apr-05 6:06
susscehrnow26-Apr-05 6:06 
GeneralRe: Line of code missing Pin
VbGuru61326-Apr-05 6:11
VbGuru61326-Apr-05 6:11 
GeneralRe: Line of code missing Pin
cehrnow26-Apr-05 6:32
susscehrnow26-Apr-05 6:32 
GeneralRe: Line of code missing Pin
VbGuru61326-Apr-05 6:43
VbGuru61326-Apr-05 6:43 
GeneralRe: Line of code missing ? Pin
cehrnow26-Apr-05 6:49
susscehrnow26-Apr-05 6:49 
GeneralRe: Line of code missing ? Pin
VbGuru61326-Apr-05 6:52
VbGuru61326-Apr-05 6:52 
GeneralRe: Line of code missing ? Pin
cehrnow26-Apr-05 6:57
susscehrnow26-Apr-05 6:57 
GeneralRe: Line of code missing ? Pin
VbGuru61326-Apr-05 6:59
VbGuru61326-Apr-05 6:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.