DataView.Filter on Time columns

  • Thread starter Thread starter Nick Carter
  • Start date Start date
N

Nick Carter

I want to create a filter on a DataView for a time column. I have a column
called StartTime in a SQL Server database which is defined as a DateTime
column but it only contains times. I want to find all rows which are after
12:00:00 so I write the following line:-

DataView dataView = new DataView(dataSet.Tables["Deliveries"],
"Substring(Convert(StartTime, 'System.String'), 12, 8) > '12:00:00'", "",
DataViewRowState.CurrentRows);

but its not very elegant. Is there a better way of expressing a time
comparison other than converting it to a string and doing a character
comparison of the substring ?

Nick Carter
 
Hello Nick

Try This

DataView dataView = new DataView(dataSet.Table
["Deliveries"],DateTime.Parse("StartTime").TimeOfDay & "
'12:00:00'", "",
DataViewRowState.CurrentRows);

Not a Good One But ok ;)
Regards ,
Rahul Shukla



-----Original Message-----
I want to create a filter on a DataView for a time column. I have a column
called StartTime in a SQL Server database which is defined as a DateTime
column but it only contains times. I want to find all rows which are after
12:00:00 so I write the following line:-

DataView dataView = new DataView(dataSet.Tables ["Deliveries"],
"Substring(Convert(StartTime, 'System.String'), 12, 8)
'12:00:00'", "",
DataViewRowState.CurrentRows);

but its not very elegant. Is there a better way of expressing a time
comparison other than converting it to a string and doing a character
comparison of the substring ?

Nick Carter


.
 
Rahul,

I don't think that that will work. In your example the expression will be
evaluated for the first row and the result will be applied to all rows. The
entire expression needs to be given to DataView so that *it* can evaluate
it.

Nick

Rahul Shukla said:
Hello Nick

Try This

DataView dataView = new DataView(dataSet.Table
["Deliveries"],DateTime.Parse("StartTime").TimeOfDay & "
'12:00:00'", "",
DataViewRowState.CurrentRows);

Not a Good One But ok ;)
Regards ,
Rahul Shukla



-----Original Message-----
I want to create a filter on a DataView for a time column. I have a column
called StartTime in a SQL Server database which is defined as a DateTime
column but it only contains times. I want to find all rows which are after
12:00:00 so I write the following line:-

DataView dataView = new DataView(dataSet.Tables ["Deliveries"],
"Substring(Convert(StartTime, 'System.String'), 12, 8)
'12:00:00'", "",
DataViewRowState.CurrentRows);

but its not very elegant. Is there a better way of expressing a time
comparison other than converting it to a string and doing a character
comparison of the substring ?

Nick Carter


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top