Click here to Skip to main content
Click here to Skip to main content

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

, 20 Apr 2005 CPOL
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

Comments and Discussions

 
QuestionHow use it in emulator? PinmemberCarlo Ingrassia12-Feb-10 0:39 
AnswerRe: How use it in emulator? PinmemberVbGuru61312-Feb-10 3:29 
Generalnice work&#65281;ask for help Pinmemberhyzfujian31-May-06 16:30 
GeneralRe: nice work&#65281;ask for help PinmemberVbGuru6139-Aug-06 9:21 
GeneralThe same without temporary file PinmemberDaniel Dusinski (www.dusinski.prv.pl)5-Mar-06 5:55 
GeneralRe: The same without temporary file PinmemberVbGuru6139-Aug-06 9:20 
Questionwhere to put the image file? Pinmembertudou6-Jul-05 18:40 
AnswerRe: where to put the image file? PinmemberVbGuru6136-Jul-05 18:49 
QuestionHow to make a copy of my database in a Pocket-pc platform Pinmemberclaudiojose22-Apr-05 9:11 
AnswerRe: How to make a copy of my database in a Pocket-pc platform PinmemberVbGuru61331-May-05 7:23 
GeneralLine of code missing Pinmemberjasonshortt20-Apr-05 10:23 
GeneralRe: Line of code missing PinmemberVbGuru61320-Apr-05 10:27 
GeneralRe: Line of code missing Pinmemberjasonshortt20-Apr-05 10:38 
GeneralRe: Line of code missing PinmemberVbGuru61320-Apr-05 10:41 
GeneralRe: Line of code missing PinmemberNSieger21-Apr-05 7:22 
GeneralRe: Line of code missing PinmemberVbGuru61321-Apr-05 7:32 
GeneralRe: Line of code missing Pinsusscehrnow26-Apr-05 6:54 
GeneralRe: Line of code missing Pinsusscehrnow26-Apr-05 7:06 
GeneralRe: Line of code missing PinmemberVbGuru61326-Apr-05 7:11 
GeneralRe: Line of code missing Pinsusscehrnow26-Apr-05 7:32 
GeneralRe: Line of code missing PinmemberVbGuru61326-Apr-05 7:43 
GeneralRe: Line of code missing ? Pinsusscehrnow26-Apr-05 7:49 
GeneralRe: Line of code missing ? PinmemberVbGuru61326-Apr-05 7:52 
GeneralRe: Line of code missing ? Pinsusscehrnow26-Apr-05 7:57 
GeneralRe: Line of code missing ? PinmemberVbGuru61326-Apr-05 7: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
Web03 | 2.8.141223.1 | Last Updated 20 Apr 2005
Article Copyright 2005 by VbGuru613
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid