Skip to main content

Past Blast

Featured Products

Stay in touch using the DEVBUSS RSS feeds.
 

News

WinCE database application for MS SQL Server 7 using eVB and XML

Written by Shakil Siraj  [author's bio]  [read 71759 times]
Edited by Derek

Download the code

Page 1  Page 2  Page 3  Page 4 

This way I could display them in a window like the following:

Looks similar to VB desktop applications? You can add more tags to suit your needs. Like I told you before, XML knows no boundaries.

The gateway ASP Code

<%
Response.ContentType = "text/xml" 'it is required for the XMLHTTP.
Response.expires = 0
%>
<?xml version="1.0" encoding="Windows-1252"?>
<%
Dim objXMLDoc
Dim objXMLElement, objXMLRoot, objXMLTopic, objXMLNodes
Dim objConnection
Dim objRecordset
Dim objRecordsetField
Dim intRecordsEffected

'This function generates the error message in XML format

public sub XMLErrorMessage
  Set objXMLRoot = objXMLDoc.createElement("errormessage")
  Set objXMLDoc.documentElement = objXMLRoot
  Set objXMLNodes = objXMLDoc.createElement("state")
  objXMLNodes.Text = objConnection.Errors(0).sqlstate
  objXMLRoot.appendChild objXMLNodes
  Set objXMLNodes = objXMLDoc.createElement("description")
  objXMLNodes.Text = objConnection.Errors(0).Description
  objXMLRoot.appendChild objXMLNodes
  Set objXMLNodes = objXMLDoc.createElement("nativeerror")
  objXMLNodes.Text = obJConnection.Errors(0).NativeError
  objXMLRoot.appendChild objXMLNodes
  ' Response.write objXMLDoc.xml
end sub

'This function translates the recordset to XML document

Public Sub createResults()
Dim intRecords, intColumns

intColumns = 0
intRecords = 0

Set objXMLRoot = objXMLDoc.createElement("recordset")
objXMLDoc.documentElement = objXMLRoot

Set objXMLTopic = objXMLDoc.createElement("columns")
objXMLDoc.documentElement.appendChild objXMLTopic

'create the list of column headers. Here I have used ID to identify their column number in a particular record
For Each objRecordsetField In objRecordset.Fields
  Set objXMLNodes = objXMLDoc.createElement("column")
  objXMLNodes.setAttribute "id", Cstr( intColumns )
  objXMLNodes.setAttribute "name", objRecordsetField.Name
  objXMLTopic.appendChild objXMLNodes
  intColumns = intColumns + 1
Next

While Not objRecordset.EOF
  Set objXMLTopic = objXMLDoc.createElement("records")
  objXMLTopic.setAttribute "id", CStr(intRecords)
  objXMLRoot.appendChild objXMLTopic
  For i = 0 To intColumns - 1
    Set objXMLNodes = objXMLDoc.createElement("col")
    if isNull ( objRecordset(i) ) then
      objXMLNodes.Text = " "
    else
      objXMLNodes.Text = trim( objRecordset(i) )
    end if
    objXMLTopic.appendChild objXMLNodes
  Next
  intRecords = intRecords + 1
  objRecordset.moveNext
Wend
objXMLRoot.setAttribute "effected", cstr( intRecords )
End Sub

Set objXMLDoc = Server.CreateObject( "MSXML2.DOMDocument" )
Set objConnection = Server.CreateObject( "ADODB.Connection" )
objConnection.Open Request( "DSN" ), Request( "user" ), Request( "pass" )
on error resume next
Set objRecordset = objConnection.Execute( Request( "sql" ), intRecordsEffected )
'on error goto 0
if objConnection.Errors.Count = 0 then
  call createResults
else
  call XMLErrorMessage
end if

response.write objXMLDoc.xml

set objConnection = nothing
set objXMLDoc = nothing
%>

Previous Page  Next Page