You are here: Programmers Reference > Programmer's Reference > Document > ExecuteQuery method

Document.ExecuteQuery Method

This method executes a SQL Select or Update command in the context of the output record for the document just scanned. Unlike ADO, this method supports un-trusted environments such as a web page from the internet security zone running in the browser’s default security environment.

Scenarios where this method is useful

Method Signature

String ExecuteQuery (string Command)

Input Parameters

Command: This is a SQL Select or Update command.

To return a single column, use a normal select statement that returns that column.

"select [Gender] from [Simple View of " & doc.DocumentName & "]"

To return the data as XML, use a SQL Select statement with the FOR XML clause.

doc.SQLSimpleDocument & " with NCSH for xml auto, root('MyRoot'),xmlschema('MyUri'),elements xsinil"

When multiple rows are possible as with edit failures, the “PATH” query must be formulated correctly with a named row element and a named root element so that the resulting XML is well-formed.

For example:

sea.Document.SQLEditFailures + " for xml PATH('EditFailure'), ROOT('EditFailures')"

This query produces the following XML output.

<EditFailures>

<!--select * from [Edit Failures] where [Serial Number] = 1 for xml path('EditFailure'), root('EditFailures')-->

<EditFailure>

<EditFailureID>000001000001</EditFailureID>

<Serial_x0020_Number>1</Serial_x0020_Number>

<Document_x0020_Name>GPAS #221666 Dual Sided</Document_x0020_Name>

<Field_x0020_Name>Name</Field_x0020_Name>

<Sheet_x0020_Number>1</Sheet_x0020_Number>

<Column_x0020_Ordinal>1</Column_x0020_Ordinal>

<Edit_x0020_Ordinal>1</Edit_x0020_Ordinal>

<Omits>-1</Omits>

<Multiples>-1</Multiples>

<Message>Area should not contain multiples. Area should not be blank. </Message>

<Value>*LL RIGHT </Value>

<FailureMode>1</FailureMode>

</EditFailure>

<EditFailure>

<EditFailureID>000001000002</EditFailureID>

<Serial_x0020_Number>1</Serial_x0020_Number>

<Document_x0020_Name>GPAS #221666 Dual Sided</Document_x0020_Name>

<Field_x0020_Name>Gender</Field_x0020_Name>

<Sheet_x0020_Number>1</Sheet_x0020_Number>

<Column_x0020_Ordinal>2</Column_x0020_Ordinal>

<Edit_x0020_Ordinal>2</Edit_x0020_Ordinal>

<Omits>-1</Omits>

<Multiples>-1</Multiples>

Area should not be blank. </Message>

<Value>*LL RIGHT </Value>

<FailureMode>1</FailureMode>

</EditFailure>

<EditFailure>

<EditFailureID>000001000002</EditFailureID>

<Serial_x0020_Number>1</Serial_x0020_Number>

<Document_x0020_Name>GPAS #221666 Dual Sided</Document_x0020_Name>

<Field_x0020_Name>Gender</Field_x0020_Name>

<Sheet_x0020_Number>1</Sheet_x0020_Number>

<Column_x0020_Ordinal>2</Column_x0020_Ordinal>

<Edit_x0020_Ordinal>2</Edit_x0020_Ordinal>

<Omits>-1</Omits>

<Multiples>-1</Multiples>

<Message>Area should not contain multiples. Area should not be blank. </Message>

<Value>*</Value>

<FailureMode>1</FailureMode>

</EditFailure>

</EditFailures>

Return Value

For Select commands, it is the query result. This return value is an empty string for an Update command. Resolved data is returned as a string. This method returns an empty string if the query returns no rows. This can happen if querying for edit failures and there are none. This return value is an empty string for an Update command.

Exceptions

The method returns an error if the query syntax is incorrect or if an execution error occurs.

NOTE: You cannot use INSERT or DELETE SQL statements at scan time because there is only one output record. Specifying an empty string is also an error.

Code Samples

Following example shows how to obtain and consume XML formatted data record within the .Net environment. Code assumes that the DocComplete event handler is active

ScanEventArgs sea

Dim MyCommand= sea.Document.SQLSimpleDocument + " wth NCSH for xml auto, root('MyRoot'),xmlschema('MyUri'),elements xsinil"

Dim xmlData As String = sea.Document.ExecuteCommand(MyCommand)

‘Consume the xml

Dim strReader As StringReader = New StringReader(xmlData)

Dim xmlReader As XmlReader = XmlReader.Create(strReader)

while (xmlReader.Read())

{

Dim NodeAsString as string = xmlReader.ReadString();

}

See Also

Document.ConnectionString

Zero-PC Footprint Scanning

 

 

See Help on Help for additional information on using this help file.

See Scantron Technical Support for additional information on technical support and training options.

See the ScanTools Suite System Requirements for further details on hardware and software requirements.

ScanTools is a suite of products; the specific information you want may appear in the help for a different module. If you don't find what you're looking for here, try one of the following:

 

Scantron Corporation

Customer Service (forms, products, and services):

1-800-SCANTRON (722-6876)

www.scantron.com

Technical Support:

1-800-445-3141

support@scantron.com

Copyright © 1998-2012 Scantron Corporation. All rights reserved. Use permitted only under license. www.scantron.com. No part of the Help or user guides may be reproduced in any form, or by any means, without express permission from Scantron Corporation.

LINKS TO THIRD PARTY SITES

This help system may contain links to third party websites ("Linked Sites"). The Linked Sites are not under the control of Scantron and Scantron is not responsible for the content of any Linked Site, including without limitation any link contained in a Linked Site or any changes or modifications to a Linked Site. Scantron is not responsible for web casting or any other form of transmission received from any Linked Site. Scantron provides Users with the ability to link the Assessment System to the Linked Sites as a convenience to you, and the inclusion of any link does not imply endorsement by Scantron of the Linked Site or any association with its operators.