Click here to Skip to main content
11,578,241 members (63,499 online)
Click here to Skip to main content

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

, 20 Apr 2005 CPOL 89K 30
Rate this:
Please Sign up or sign in to vote.
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:

<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)
    ' 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)

Share

About the Author

VbGuru613
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
QuestionHow use it in emulator? Pin
Carlo Ingrassia11-Feb-10 23:39
memberCarlo Ingrassia11-Feb-10 23:39 
AnswerRe: How use it in emulator? Pin
VbGuru61312-Feb-10 2:29
memberVbGuru61312-Feb-10 2:29 
Generalnice work&#65281;ask for help Pin
hyzfujian31-May-06 15:30
memberhyzfujian31-May-06 15:30 
GeneralRe: nice work&#65281;ask for help Pin
VbGuru6139-Aug-06 8:21
memberVbGuru6139-Aug-06 8:21 
GeneralThe same without temporary file Pin
Daniel Dusinski (www.dusinski.prv.pl)5-Mar-06 4:55
memberDaniel Dusinski (www.dusinski.prv.pl)5-Mar-06 4:55 
GeneralRe: The same without temporary file Pin
VbGuru6139-Aug-06 8:20
memberVbGuru6139-Aug-06 8:20 
Questionwhere to put the image file? Pin
tudou6-Jul-05 17:40
membertudou6-Jul-05 17:40 
AnswerRe: where to put the image file? Pin
VbGuru6136-Jul-05 17:49
memberVbGuru6136-Jul-05 17:49 
QuestionHow to make a copy of my database in a Pocket-pc platform Pin
claudiojose22-Apr-05 8:11
memberclaudiojose22-Apr-05 8:11 
AnswerRe: How to make a copy of my database in a Pocket-pc platform Pin
VbGuru61331-May-05 6:23
memberVbGuru61331-May-05 6:23 
GeneralLine of code missing Pin
jasonshortt20-Apr-05 9:23
memberjasonshortt20-Apr-05 9:23 
GeneralRe: Line of code missing Pin
VbGuru61320-Apr-05 9:27
memberVbGuru61320-Apr-05 9:27 
GeneralRe: Line of code missing Pin
jasonshortt20-Apr-05 9:38
memberjasonshortt20-Apr-05 9:38 
GeneralRe: Line of code missing Pin
VbGuru61320-Apr-05 9:41
memberVbGuru61320-Apr-05 9:41 
GeneralRe: Line of code missing Pin
NSieger21-Apr-05 6:22
memberNSieger21-Apr-05 6:22 
GeneralRe: Line of code missing Pin
VbGuru61321-Apr-05 6:32
memberVbGuru61321-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
memberVbGuru61326-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
memberVbGuru61326-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
memberVbGuru61326-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
memberVbGuru61326-Apr-05 6:59 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 20 Apr 2005
Article Copyright 2005 by VbGuru613
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid