473,324 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

DataView RowFilter Closest Date

I have a DataView (dv) that includes a StartDate DateTime column. I'd like to
return the DataView record that contains a StartDate value closest to my
IncidentDate value:

string filter = String.format("StartDate nearest {0}", IncidentDate);

dv.Rowfilter = filter;

Of course, there's no nearest function.

The IncidentDate could be anywhere in the range of StartDate values, so
simply sorting by the StartDate and taking the top record isn't good enough.

It appears that dv.Find() only accept objects. Otherwise that would work
pretty well.

Any suggestions?

Thanks,
--
Randy
Sep 11 '06 #1
3 10201
Randy,

You are going to have to do this on your own. You will have to cycle
through all the rows and then keep track of the value you are looking for
(whichever one is closest to your date).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"randy1200" <ra*******@newsgroups.nospamwrote in message
news:E1**********************************@microsof t.com...
>I have a DataView (dv) that includes a StartDate DateTime column. I'd like
to
return the DataView record that contains a StartDate value closest to my
IncidentDate value:

string filter = String.format("StartDate nearest {0}", IncidentDate);

dv.Rowfilter = filter;

Of course, there's no nearest function.

The IncidentDate could be anywhere in the range of StartDate values, so
simply sorting by the StartDate and taking the top record isn't good
enough.

It appears that dv.Find() only accept objects. Otherwise that would work
pretty well.

Any suggestions?

Thanks,
--
Randy

Sep 11 '06 #2
Hi Randy,

I agree with Nicholas. Since the expression column doesn't support
operators on DateTime, we have to go through each row and do the comparison
on our own.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Sep 12 '06 #3
Tom
Kevin,

I am trying to do something similar...I am getting lost a little on the
references to "expression column"...and their not supporting operators on
DateTime....I am not sure if that is in fact my issue...code sample
follows....

I am trying to simply apply a filter, two-of-three columns are date
types...My DataView.Count is zero after the filter is set....see code snip...

/**************
// 2) get the EventLogKey from the Event History table
DataView dvEventHist =
this.m_ds.Tables[TABLE_EVENT_HISTORY].DefaultView;

string filter = String.Format("TagName = '{0}' and DateTime =
#{1}# and DetectDateTime = #{2}#",
drv["Event"],
drv["EventTime"],
drv["DetectionTime"]);

dvEventHist.RowFilter = filter;

// QWERTY --- manually search the event history
bool found = false;
foreach (DataRow dr in this.m_ds.Tables[TABLE_EVENT_HISTORY].Rows)
{
if (dr["TagName"].Equals(drv["Event"]) &&
dr["DateTime"].Equals(drv["EventTime"]) &&
dr["DetectDateTime"].Equals(drv["DetectionTime"]))
{
found = true;
}

found = false;
}

// QWERTY -- try selecting from the datatable....also does not
work
DataRow[] selRows =
this.m_ds.Tables[TABLE_EVENT_HISTORY].Select(filter);
if (selRows.Length 0)
{
}
**************/

I do not understand why the DataView.RowFilter (and apparently also the
DataTable.Select(filter) ) do not make row matches...when cycling through the
rows manually I find what I expect...???

OK...so maybe that is what I have to do...I do not understand WHY...?

Thanks.
"Kevin Yu [MSFT]" wrote:
Hi Randy,

I agree with Nicholas. Since the expression column doesn't support
operators on DateTime, we have to go through each row and do the comparison
on our own.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vern | last post by:
The following code retrieves data into a dataset, and then creates a dataview with a filter. This dataview is then attached to a combobox. When the effective date changes, I would like to see the...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
2
by: Ryan Moore | last post by:
I have a dataset (called adset) which has a column called "Large" which is either an integer 0 or 1. I am creating 2 dataviews, one which should display the 1's and one which should display the...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
10
by: Roy Lawson | last post by:
Can anyone explain the difference between RowStateFilter and RowFilter properties of the DataView objects in simple terms? I am going through a Transcender practice exam and just when I think I...
1
by: Luis Mendes | last post by:
I have a Table wicth as the Field: Date in the Date/Time format and stores data like dd-MM-yyyy hh:mm:ss. I can I set the Dataview.Rowfilter to filteran especific date no mathers the Time? I've...
2
by: IndyChris | last post by:
I have DataView of DataSet. I want to filter the DataView by the date. dvEvents.RowFilter = "BegDate >= '" + dateTimePicker1.Value.Date + "' BegDate <= '" + dateTimePicker2.Value.Date.AddDays(1) +...
1
by: AlexW | last post by:
Hi I am in the process of developing an inventory application in visual basic. I keep coming up against a problem with using the dataview.rowfilter property. Basically what happens is this: -a...
5
by: AlexW | last post by:
Hi I am in the process of developing an inventory application in visual basic. I keep coming up against a problem with using the dataview.rowfilter property. Basically what happens is this: -a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.