Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Twitter Updates

    News

    New site design will be posted by Wednesday.
    6/2/2008 8:07:00 AM

    Windows Mobile Developer Controls
    Sapphire Soltuions
    Skip Navigation Links Breadcrumb Articles Breadcrumb Past Blast BreadcrumbeVB Database

    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 

    The eVB Code

    These eVB functions I have produced which are look-a-like of ADOCE.Recordset object functions. But they have the same basic functionalities:

    This getNumberOfRows() function returns the number of records in the XML file which we can use for the 'for' loop. Look into the "effected" attribute of the root node.

    Public Function getNumberOfRows() As Integer
    getNumberOfRows = CInt(objXMLDoc.documentElement.getAttribute("effected"))
    End Function

    This is the main query operation and creates the connection to the ASP page using XMLHTTP component. The return of the "GET" / "POST" operation to our gateway (ASP Page running under IIS) is also a XML document. If the SQL operation on the server was successful, the name of the root node will be "recordset" otherwise "errormessage". Based on the node values it will set the response XML doc to the appropriate XML doc and return a Boolean value.

    It calls the function "createConnection" with appropriate username, password and SQL query and waits for the response from the gateway. If the result is false then it returns false as the result of the query operation on the gateway (you can look into the objXMLError object to retrieve the error values). If the result is positive then it initializes all the appropriate variables and returns true. Remember to change the server IP address if required.

    Public Function createConnection(ByVal DSN As String, ByVal username As String, ByVal password As String, ByVal query As String) As Boolean

    Form1.Label2.Caption = "Connection to the system. Please wait..."
    objXMLGatewayConnection.Open "GET", "http://127.0.0.1:8080/dbconnector.asp?DSN=" & DSN & "&user=" & username & "&pass=" & password & "&sql=" & query, False
    objXMLGatewayConnection.send
    If objXMLGatewayConnection.responseXML.documentElement.nodeName = "errormessage" Then
    Set objXMLError = objXMLGatewayConnection.responseXML
    createConnection = False
    Exit Function
    End If
    Set objXMLDoc = objXMLGatewayConnection.responseXML
    Form1.Label2.Caption = ""
    createConnection = True
    End Function

    Public Function executeQuery(ByVal DSN As String, ByVal username As String, ByVal   password As String, ByVal qry As String) As Boolean
      intCurrentRow = -1
      If createConnection(DSN, username, password, qry) = False Then
        executeQuery = False
        Exit Function
      End If
      intCurrentRow = 0
      intMaxRows = getNumberOfRows
      executeQuery = True
    End Function

    Increase the current row number by one

    Public Sub moveNext()
      intCurrentRow = intCurrentRow + 1
    End Sub

    Decrease the current row number by one

    Public Sub movePrevious()
      intCurrentRow = intCurrentRow - 1
    End Sub

    Move to the record number 0

    Public Sub moveFirst()
      intCurrentRow = 0
    End Sub

    Move to the appropriate position as the parameter "pos"

    Public Sub move(ByVal pos As Integer)
      intCurrentRow = pos
    End Sub

    This function checks if you have reached the last row in the XML document

    Public Function EOF() As Boolean
      If intCurrentRow < intMaxRows Then
        EOF = False
      Else
        EOF = True
      End If
    End Function

    This function checks if you are at the beginning of the recordset

    Public Function BOF() As Boolean
      If intCurrentRow = 0 Then
        BOF = True
      Else
        BOF = False
      End If
    End Function

    This function retrieves the id number of any column. This is used to determine the exact child number of the "records" child nodes to which this node name belongs.

    Public Function getColumnIndex(ByVal columnName As String) As Integer
      getColumnIndex =     CInt(objXMLDoc.documentElement.selectSingleNode("//column[@name='" &     columnName & "']").Attributes.getNamedItem("id").text)
    End Function

    This function returns the value of the column as specified by the "columnName" parameter at the current row position.

    Public Function recordSet(ByVal columnName As String) As String
      recordSet = objXMLDoc.documentElement.selectSingleNode("//records[@id='" +   CStr(intCurrentRow) + "']").childNodes.Item(getColumnIndex(columnName)).text
    End Function

    This function returns the value of the column as specified by the "columnName" parameter at the row position specified by the parameter "position".

    Public Function recordSetAt(ByVal columnName As String, ByVal position As Integer) As String
      recordSetAt = objXMLDoc.documentElement.selectSingleNode("//records[@id='" +   CStr(position) + "']").childNodes.Item(getColumnIndex(columnName)).text
    End Function

    Previous Page  Next Page