Client Interfaces Guide > Connecting to TDV Server through ADO.NET > Sample Code for Testing of an ADO.NET Driver > Select Data from a TDV Published Resource on the Server
 
Select Data from a TDV Published Resource on the Server
Here is another example illustrating a data selection from the server.
public void TestExecuteReader()
{
try
{
CompositeCommand cmd = new CompositeCommand("select ProductID,ProductName from products where ProductID=1111",GetConnection());
CompositeDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
int ProductID = reader.GetInt32(0);
String ProductName = reader.GetString("ProductName");
Console.WriteLine("(ProductID:" + ProductID + ",ProductName:" + ProductName + "TestExecuteReader)");
}
reader.Close();
}
catch (Exception ex)
{
throw ex;
}
}
To select data from a published resource on the server
1. Call cmd.ExecuteReader to get a CompositeDataReader object.
2. Access result set data using the CompositeDataReader object. The Read method tells you whether there is row data. If the Read method result value is true, columns are accessible by their respective ordinal integer or by column name. The ordinal integer numbering begins with 0, not with 1.
3. To get the first column value of the current row, use the statement:
int ProductID = reader.GetInt32(0);
 
4. Because the object in that column is an integer, the GetInt32 method retrieves the value. If the column type were a string, the GetString (column name|column ordinal) method would retrieve the value.
5. Close the reader using reader.Close().
If the reader is not closed, errors occur.