473,803 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10261
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.co m

"randy1200" <ra*******@news groups.nospamwr ote in message
news:E1******** *************** ***********@mic rosoft.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.Table s[TABLE_EVENT_HIS TORY].DefaultView;

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

dvEventHist.Row Filter = filter;

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

found = false;
}

// QWERTY -- try selecting from the datatable....al so does not
work
DataRow[] selRows =
this.m_ds.Table s[TABLE_EVENT_HIS TORY].Select(filter) ;
if (selRows.Length 0)
{
}
**************/

I do not understand why the DataView.RowFil ter (and apparently also the
DataTable.Selec t(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
11452
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 newly filtered data without having to create a new dataview each time. Is that possible? Also, do I need to attach the dataview to the combo box each time? if (AgencyCounties == null || sPropertyState.Text != prevPropertyState) {...
2
3312
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 the selected lie item at which case I would pop up a separate dialog box to do so, in the debugging code, the dataview.count would return 0. I get a error message because I tried to get values out of a dataview that holds 0 items. Does anyone...
2
2305
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 0's using the following code: DataView largeview = new DataView(); largeview.RowFilter = "Large=1"; largeview.Table = adSet1.Tables; DataView smallview = new DataView();
8
3902
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 = "'Record ID' = '0'"; theView.RowStateFilter = DataViewRowState.ModifiedCurrent; Debug.WriteLine(string.Format("RowFilter = {0}", theView.RowFilter)); RecordDataGrid.DataSource = theView; RecordDataGrid.DataBind();
10
11169
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 understand the difference I miss the question. Didn't pass the 306 exam two weeks ago and don't want to repeat that again <<scored 680, needed 700 :- ( >>
1
3199
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 tryed several ways Me.DataView1.RowFilter=Date='#17-10-2005 %#'. Thanks in advance Luis
2
1985
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) + "'"; My problem is that the filter is getting the wrong values. dateTimePicker1.Value = 8/2/2006 dateTimePicker2.Value = 8/3/2006 You would only expect records with 8/2 or 8/3 to show up. I'm getting all records that are 8/2 and 8/2X.
1
2713
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 global dataview is created -The user enters new part information into a form. -A function is called to check to see if the part is a new part (so that two identical part numbers are not added to the database. -The check is done by setting the...
5
11843
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 global dataview is created -The user enters new part information into a form. -A function is called to check to see if the part is a new part (so that two identical part numbers are not added to the database. -The check is done by setting the...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.