tags:

views:

779

answers:

3

Does SubSonic.SqlQuery have a between/and for date ranges? If not, what would be the best way to get a range.

+3  A: 

Try something like this:

SqlQuery query = new SqlQuery().From("Table")
                               .WhereExpression("Column")
                               .IsBetweenAnd("1/1/2008", "12/31/2008");
DataSet dataSet = query.ExecuteDataSet();  // Or whatever output you need
Forgotten Semicolon
Here's another snippet.. which ended up being my solution...And(Order.OrderDateColumn).IsBetweenAnd(lastRunDate,System.DateTime.Now);
madcolor
Glad it worked for you.
Forgotten Semicolon
+2  A: 
aherrick
A: 

Combined Northwind answer:

     SqlQuery query = new SqlQuery().From("Orders")
                   .WhereExpression("OrderDate")
                   .IsBetweenAnd("1996-07-02", "1996-07-08");
     DataSet dataSet = query.ExecuteDataSet();  // Or whatever output you need

     #region PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp

     DataTable dt = dataSet.Tables[0];
     Response.Write("<table>");
     foreach ( DataRow dr in dt.Rows ) 
     {
      Response.Write("<tr>");
       for (int i = 0; i < dt.Columns.Count; i++)
       {
        Response.Write("<td>");
        Response.Write(dr[i].ToString() + " ");
        Response.Write("<td>");
       } //eof for 
       Response.Write("</br>");
       Response.Write("</tr>");


     }
     Response.Write("<table>");
     #endregion PresentResultsReplaceResponseWriteWithConsole.WriteLineForConsoleApp
YordanGeorgiev