title | TOCTitle | description | ms:assetid | ms:mtpsurl | ms:contentKeyID | ms.date | mtps_version | f1_keywords | dev_langs | api_location | api_name | api_type | topic_type | product_family_name | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
QueryResult Class (Microsoft.Web.Management.DatabaseManager) |
QueryResult Class |
The QueryResult class represents a query result that was returned from a database query. This article describes its syntax, constructors, properties, and methods. |
T:Microsoft.Web.Management.DatabaseManager.QueryResult |
20476472 |
05/02/2012 |
v=VS.90 |
|
|
|
|
|
|
VS |
Represents a query result that was returned from a database query.
System.Object
Microsoft.Web.Management.DatabaseManager.QueryResult
Namespace: Microsoft.Web.Management.DatabaseManager
Assembly: Microsoft.Web.Management.DatabaseManager (in Microsoft.Web.Management.DatabaseManager.dll)
'Declaration
Public Class QueryResult
'Usage
Dim instance As QueryResult
public class QueryResult
public ref class QueryResult
public class QueryResult
The QueryResult type exposes the following members.
Method Type | Name | Description |
---|---|---|
![]() |
QueryResult | Creates a new instance of the QueryResult class. |
Property Type | Name | Description |
---|---|---|
![]() |
ColumnMetadata | Returns a list of column metadata for a query result. |
![]() |
QueryResults | Retrieves an array of query results. |
Method Type | Name | Description |
---|---|---|
![]() |
Equals | (Inherited from Object.) |
![]() |
Finalize | (Inherited from Object.) |
![]() |
GetHashCode | (Inherited from Object.) |
![]() |
GetType | (Inherited from Object.) |
![]() |
MemberwiseClone | (Inherited from Object.) |
![]() |
ToString | (Inherited from Object.) |
The following code sample illustrates an example ExecuteQuery method that returns an array of query results from a database query.
Public Overrides Function ExecuteQuery( _
ByVal connectionString As String, _
ByVal query As Microsoft.Web.Management.DatabaseManager.Query) _
As Microsoft.Web.Management.DatabaseManager.QueryResult()
Dim results As List(Of QueryResult) = New List(Of QueryResult)
Dim result As QueryResult = New QueryResult
Try
' Create a new OLEDB connection using the connection string.
Dim connection As OleDbConnection = New OleDbConnection(connectionString)
Dim command As OleDbCommand = New OleDbCommand(query.Statement, connection)
' Open the database connection.
connection.Open()
' Execute the query and access the data.
Dim reader As OleDbDataReader = command.ExecuteReader
' Add the results to the query list.
results.Add(GetQueryResult(reader))
' Close the database connection.
reader.Close()
' Return the query results.
Return results.ToArray
Catch ex As Exception
Throw New ProviderException(ex.Message)
End Try
End Function
...
Private Function GetQueryResult(ByVal reader As OleDbDataReader) As QueryResult
Dim result As QueryResult = New QueryResult
Dim fieldCount As Integer = reader.FieldCount
Dim i As Integer = 0
Do While (i < fieldCount)
Dim metadata As QueryColumnMetadata = New QueryColumnMetadata
metadata.Name = reader.GetName(i)
result.ColumnMetadata.Add(metadata)
i = (i + 1)
Loop
While reader.Read
Dim itemData() As Object = New Object((fieldCount) - 1) {}
i = 0
Do While (i < fieldCount)
itemData(i) = ConvertToSerializable(reader(i))
i = (i + 1)
Loop
result.QueryResults.Add(itemData)
End While
Return result
End Function
public override QueryResult[] ExecuteQuery(
string connectionString,
Query query )
{
List<QueryResult> results = new List<QueryResult>();
QueryResult result = new QueryResult();
try
{
// Create a new OLEDB connection using the connection string.
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(query.Statement, connection);
// Open the database connection.
connection.Open();
// Execute the query and access the data.
OleDbDataReader reader = command.ExecuteReader();
// Add the results to the query list.
results.Add(GetQueryResult(reader));
// Close the database connection.
reader.Close();
}
// Return the query results.
return results.ToArray();
}
catch(Exception ex)
{
throw new ProviderException(ex.Message);
}
}
...
private QueryResult GetQueryResult(OleDbDataReader reader)
{
QueryResult result = new QueryResult();
int fieldCount = reader.FieldCount;
for (int i = 0; i < fieldCount; i++)
{
QueryColumnMetadata metadata = new QueryColumnMetadata();
metadata.Name = reader.GetName(i);
result.ColumnMetadata.Add(metadata);
}
while (reader.Read())
{
object[] itemData = new object[fieldCount];
for (int i = 0; i < fieldCount; i++)
{
itemData[i] = ConvertToSerializable(reader[i]);
}
result.QueryResults.Add(itemData);
}
return result;
}
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.