The following codes have illustrated how to run OQL.NET statements through ADO.NET and deal with the query result with DataReader.
|
using (IDbConnection conn = new SqlConnection(connStr)) { conn.Open(); // The following line sets the OQL.NET to the default
value SQL Server. You only need to set it once through the whole program
writing process. // CustomSqlBuilder.Default supports SQL Server and
Oracle by default. OQL.DefaultSqlBuilder = CustomSqlBuilder.SqlServer; // Querying all lines in the Orders table SelectQuery query = OQL.SelectFrom(NW.Order); IDbCommand cmd = conn.CreateCommand(); cmd.CommandText = query.ToString(); // The following line is equivalent to the previous
one. cmd.CommandText = (string)query; cmd.CommandType = CommandType.Text; IDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // Using strong type Console.WriteLine(reader[(string)NW.Order.OrderID]); // using string Console.WriteLine(reader["OrderDate"]); } reader.Close(); } |
Related Topics