0 Replies - 470 Views - Last Post: 22 July 2013 - 07:40 PM Rate Topic: -----

#1 toad87   User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 197
  • Joined: 21-May 12

Comparing SQL Date with .Net DateTime in DataTable Select

Posted 22 July 2013 - 07:40 PM

I'm trying to use DataTable's Select method to return rows. The expression compares my DataTable's "date" column with a DateTime retrieved from a DateTimePicker.

The problem I'm getting is that the DateTime from the Picker contains the time as well as date.

I get a SyntaxErrorException; Syntax error: Missing operand after '12' operator.

The '12' is the hour.

 DataTable appointmentViewTable = this.brandpk2_UptownLashesDataSet2.Tables["Appointments_View"];
            DataTable filteredAppointmentViewTable = new DataTable();
            DataRow[] returnedRows = null;

            string dateExpression = string.Format("date < {0}", this.dateTimePickerFromDate.Value.Date);

            returnedRows = appointmentViewTable.Select(dateExpression );

            foreach (DataRow row in returnedRows)

            this.dataGridViewAppointmentsView.DataSource = null;
            this.dataGridViewAppointmentsView.DataSource = filteredAppointmentViewTable;

DateTime.Date still yields a time result of 12:00:00:00 after the date...

How do I get around this?


I was looking at my DataTable and it looks like the 'Date' column's data type is System.DateTime....So I have no idea why I'm getting the exception...


I was missing single quotes around my DateTime value....

Should have been like this: "Date < '{0}'".

This post has been edited by toad87: 22 July 2013 - 07:54 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1