The following codes have illustrated how to run OQL.NET statements through ADO.NET and to deal with the query results with DataSet:
|
using (SqlConnection 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); SqlCommand cmd = new SqlCommand((string)query, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); foreach (DataRow row in ds.Tables[0].Rows) { // Using strong type Console.WriteLine(row[(string)NW.Order.OrderID]); // using string Console.WriteLine(row["OrderDate"]); } } |
The following codes have illustrated how to use the strong-typed table name.
|
DataSet ds = new DataSet(); ds.Tables.Add((string)NW.Order); da.Fill(ds.Tables[(string)NW.Order]); foreach (DataRow row in ds.Tables[(string)NW.Order].Rows) { } |
Related Topics