retrieve lots of values using linq RRS feed

  • Question

  • For a 2010 application that I am working on I a am trying to determine how to write a linq to sql statement for the following:

    select date1, date2, date3,date4, date5,date6

     from dbo.Schedule.table
    where datepart(mm,payment_month)= 01 and datepart(yyyy,payment_month) =2011

    This table is entirely a schedule table. They key to the table is not worth using since it is an identity column that exists for the purpose of creating the table.

    The month and year values would come in as parameters from two dropdownlist controls.

    Thus could you tell me how to setup this linq to sql statement?


    Friday, November 11, 2011 5:46 PM


  • Hi midnight_car;

    In the following query it assumes that payment_month is NOT nullable. If it is nullable then the where clause changes to the following:

    where s.payment_month.Value.Month == month && s.payment_month.Value.Year == year

    int month = int.Parse(dropdownlistMonth.Text);
    int year = int.Parse(dropdownlistYear.Text);
    // Assumes that payment_month is NOT nullable.
    var results = from s in DataContext.TableName
    		where s.payment_month.Month == month && s.payment_month.Year == year
    		select new
    			date1 = s.date1,
    			date2 = s.date2,
    			date3 = s.date3,
    			date4 = s.date4,
    			date5 = s.date5,
    			date6 = s.date6			


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by midnight_car Friday, November 11, 2011 7:11 PM
    Friday, November 11, 2011 6:41 PM