473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB.net Dataview Rowfilter behaviour problems

11 New Member
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.rowfil ter 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 rowfilter value to the string representation of the partnumber and checking if the dataview's .count method returns 0 (ie the rowfilter that was applied hides everything)
-if the function returns true then the .addnew() method of the dataview is invoked and the part details are added to the dataview. (the updating of the actual database will be done later through a user dialog)

The above works perfectly for the first part number but not for any parts added after this. The reason is that for some reason the rowfilter that is applied does not filter out the newly added part, even though the row filter should have filtered this part out because the part Numbers are completely different.
I have checked that the values are being correctly set by stepping through the function line by line and have also made sure that no other functions are being called during its execution.

Any Ideas?

Here is the code of the function below:

Expand|Select|Wrap|Line Numbers
  1. Private Function checkPartIsNew(ByVal partNumber As String) As Boolean
  2.         Dim filterString As String
  3.  
  4.         'variables used for debugging purposes only
  5.         Dim test As DataRowView 'for testing
  6.         Dim testpartNum As String 'for testing
  7.         Dim messageString As String 'for testing
  8.  
  9.         'checking to see if a row filter already exists
  10.         addPartsDataView.RowStateFilter = DataViewRowState.OriginalRows
  11.         If IsNothing(addPartsDataView.RowFilter) = False Then
  12.  
  13.             messageString = "rowFilterApplied, "
  14.  
  15.             'there must already be a rowfilter applied, take steps to preserve it
  16.             filterString = addPartsDataView.RowFilter
  17.             addPartsDataView.RowFilter = Nothing 'put in during debugging to ensure row filter is removed
  18.  
  19.             'set row filter to partNumber
  20.             addPartsDataView.RowFilter = "partNum = '" + partNumber + "'"
  21.  
  22.             'test if part is new/unique
  23.             If addPartsDataView.Count = 0 Then
  24.                 'part must be unique (filter returns no rows)
  25.                 'reapply filter
  26.                 addPartsDataView.RowFilter = filterString
  27.                 Return True
  28.             End If
  29.  
  30.             messageString = messageString + "Addpartsdataview.count equals " + addPartsDataView.Count.ToString + ", "
  31.  
  32.         Else
  33.             'no row filter is currently applied
  34.             messageString = "No row filter applied, "
  35.             addPartsDataView.RowFilter = Nothing
  36.  
  37.             'set row filter to partNumber
  38.             addPartsDataView.RowFilter = "partNum = '" + partNumber + "'"
  39.  
  40.             'test if part is new/unique
  41.             If addPartsDataView.Count = 0 Then
  42.             'part must be unique (filter returns no rows)
  43.                 'remove filter
  44.                 addPartsDataView.RowFilter = Nothing
  45.                 Return True
  46.             End If
  47.  
  48.             messageString = messageString + "Addpartsdataview.count equals " + addPartsDataView.Count.ToString + ", "
  49.  
  50.         End If
  51.  
  52.         'for debugging only
  53.         test = addPartsDataView(0)
  54.         testpartNum = test.Item("PartNum")
  55.         MsgBox(messageString)
  56.  
  57.         'if we are here then part already exists
  58.         Return False
  59.     End Function 
Any Help Would be most appreciated.

Thanks in advance
Oct 19 '07 #1
5 11841
kenobewan
4,871 Recognized Expert Specialist
My guess is that your dataview is losing the subsequent rows by not storing them, that is why addnewrow is usually followed by a data update. HTH.
Oct 21 '07 #2
AlexW
11 New Member
My guess is that your dataview is losing the subsequent rows by not storing them, that is why addnewrow is usually followed by a data update. HTH.
Sorry I don't follow your reasoning, why would I need to update the database I got the original data from with each row I add? Why can't I make my changes to a local dataset and then update all the changes at once?

what is happening here is that the rowfilter is getting is not filtering out newly added rows. ie the test below should be returning 0 when I give it a partnumber which is unique, but instead returns the number of the rows that I have already added (note that they all have completely different part numbers too)

The excerpt of code I'm referring to is shown below

Expand|Select|Wrap|Line Numbers
  1. 'set row filter to partNumber
  2. addPartsDataView.RowFilter = "partNum = '" + partNumber + "'"
  3. 'test if part is new/unique
  4. If addPartsDataView.Count = 0 Then
  5. 'part must be unique (filter returns no rows) 
Oct 22 '07 #3
AlexW
11 New Member
I just noticed that the .haschanges property of the dataset that my dataview refers to remains false after adding a row. Could this have something with it?

The code for adding a new datarow is shown below... am I missing a step?

Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim addedRow As System.Data.DataRowView
  3.         'creating new row in dataview, making addedRow point to it
  4.         addedRow = addPartsDataView.AddNew()  
  5.  
Oct 22 '07 #4
AlexW
11 New Member
Problem solved

I had to either create a binding source and call the .endedit() method on it or change the selected row.

I chose the former. My revised working code to add a new datarow to the dataset is shown below:

Expand|Select|Wrap|Line Numbers
  1. Private Function fillDataRowfromForm() As System.Data.DataRowView
  2.  
  3.         Dim myBindingSource As BindingSource = New BindingSource
  4.         myBindingSource.DataSource = addPartsDataView
  5.         'myDataGridView.DataSource = myBindingSource;
  6.  
  7.         Dim addedrow As DataRowView = DirectCast(myBindingSource.AddNew(), DataRowView)
  8.  
  9.         addedRow.Item("Major") = ....
  10.         addedRow.Item("Minor") = ....
  11.  
  12.         addedrow.EndEdit()
  13.  
  14.     End Function
Hope this helps anyone else with the same problem.
Oct 22 '07 #5
baysoftdan
3 New Member
Hi there.

Can I suggest that you abandon this method of checking for duplicates.
I would personally create a function called

Expand|Select|Wrap|Line Numbers
  1. Protected Sub ExecuteScalar(byVal SQL as String) as Object
Basically, you need to create a new system.data.sql client.sqlconne ction object,
then a new system.data.sql client.sqlcomma nd object and then fire the command using ExecuteScalar as the method, returning the result of the query as the result of the function.

Basically, you can then run some code similar to this:

Expand|Select|Wrap|Line Numbers
  1. If ExecuteScalar("select count(*) from [cust] where [email] = 'email@address.com' ") > 0 THEN
  2.   ' Give some bad feedback
  3. else
  4.   ' Proceed with the insertion of the new record
  5. End If
Right tool for the right job.

I hope this helps.
Oct 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2113
by: Webgour | last post by:
I'm tring to filter a dataview with multiple rowfilters. The problem is that each time I use RowFilter on the DataView i'm quering the full dataview as it was loaded, not the filtered version. Is there any way to get the Dataview to keep track of the different RowFilter used?
3
11448
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
2304
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
3899
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();
8
4783
by: KC | last post by:
For a DataView.Rowfilter can I use more than one expression? I want to filter out two different things. For example can I take: dv.RowFilter = "MTX <> 'Customer Forcast'" and dv.RowFilter = "MTX <> 'Actual vs. Forcast'"
7
10211
by: randy1200 | last post by:
I have an orders table. Each record in the orders table contains a customer id. I have a customer table. The primary key of each record in the customer table is the customer id. After getting a subset from the orders table, I need to take the customer ids in the orders table subset, and list each record in the customer table that has a matching customer id. If I were in t-sql, this would be an easy inner join. In this case, I get
0
1525
by: neeraj | last post by:
Hi, all Could anny one give me help how can I use like operator with these data types "integer , datetime or boolean" in DataView.RowFilter Actually when I try to get the data from dataview using rowfilter with like operator Its working fine when data type of searching column is "string" . But if data type is "integer , datetime or boolean" its throws
2
18941
by: neeraj | last post by:
Hi, all Could anny one give me help how can I use like operator with these data types "integer , datetime or boolean" in DataView.RowFilter Actually when I try to get the data from dataview using rowfilter with like operator Its working fine when data type of searching column is "string" . But if data type is "integer , datetime or boolean" its throws
1
2711
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
9554
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
9988
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
9923
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
9811
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
8813
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...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
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();...
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
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.