ExecuteReader(CommandBehavior) Method
The following example creates a
SugarCommand, 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 CreateSugarDataReader(string mySelectQuery,string sugarConnectionString)
{
SugarConnection sugarConnection = new SugarConnection(sugarConnectionString);
SugarCommand sugarCommand = new SugarCommand(mySelectQuery, sugarConnection);
sugarCommand.Connection.Open();
SugarDataReader sugarReader = sugarCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(sugarReader.Read())
{
Console.WriteLine(sugarReader.GetString(0));
}
sugarReader.Close();
}
Public Sub CreateSugarDataReader(mySelectQuery As String, _
sugarConnectionString As String)
Dim sugarConnection As New SugarConnection(sugarConnectionString)
Dim sugarCommand As New SugarCommand(mySelectQuery, sugarConnection)
sugarCommand.Connection.Open()
Dim sugarReader As SugarDataReader = sugarCommand.ExecuteReader(CommandBehavior.CloseConnection)
While sugarReader.Read()
Console.WriteLine(sugarReader.GetString(0))
End While
sugarReader.Close()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2