ExecuteReader(CommandBehavior) Method
The following example creates a
FreshBooksCommand, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source. The
System.Data.CommandBehavior is then set to CloseConnection.
|
|---|
public void CreateFreshBooksDataReader(string mySelectQuery,string freshBooksConnectionString)
{
FreshBooksConnection freshBooksConnection = new FreshBooksConnection(freshBooksConnectionString);
FreshBooksCommand freshBooksCommand = new FreshBooksCommand(mySelectQuery, freshBooksConnection);
freshBooksCommand.Connection.Open();
FreshBooksDataReader freshBooksReader = freshBooksCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(freshBooksReader.Read())
{
Console.WriteLine(freshBooksReader.GetString(0));
}
freshBooksReader.Close();
} |
|
|---|
Public Sub CreateFreshBooksDataReader(mySelectQuery As String, _
freshBooksConnectionString As String)
Dim freshBooksConnection As New FreshBooksConnection(freshBooksConnectionString)
Dim freshBooksCommand As New FreshBooksCommand(mySelectQuery, freshBooksConnection)
freshBooksCommand.Connection.Open()
Dim freshBooksReader As FreshBooksDataReader = freshBooksCommand.ExecuteReader(CommandBehavior.CloseConnection)
While freshBooksReader.Read()
Console.WriteLine(freshBooksReader.GetString(0))
End While
freshBooksReader.Close()
End Sub |