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:
Any Help Would be most appreciated.
Thanks in advance
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:
Code:
Private Function checkPartIsNew(ByVal partNumber As String) As Boolean Dim filterString As String 'variables used for debugging purposes only Dim test As DataRowView 'for testing Dim testpartNum As String 'for testing Dim messageString As String 'for testing 'checking to see if a row filter already exists addPartsDataView.RowStateFilter = DataViewRowState.OriginalRows If IsNothing(addPartsDataView.RowFilter) = False Then messageString = "rowFilterApplied, " 'there must already be a rowfilter applied, take steps to preserve it filterString = addPartsDataView.RowFilter addPartsDataView.RowFilter = Nothing 'put in during debugging to ensure row filter is removed 'set row filter to partNumber addPartsDataView.RowFilter = "partNum = '" + partNumber + "'" 'test if part is new/unique If addPartsDataView.Count = 0 Then 'part must be unique (filter returns no rows) 'reapply filter addPartsDataView.RowFilter = filterString Return True End If messageString = messageString + "Addpartsdataview.count equals " + addPartsDataView.Count.ToString + ", " Else 'no row filter is currently applied messageString = "No row filter applied, " addPartsDataView.RowFilter = Nothing 'set row filter to partNumber addPartsDataView.RowFilter = "partNum = '" + partNumber + "'" 'test if part is new/unique If addPartsDataView.Count = 0 Then 'part must be unique (filter returns no rows) 'remove filter addPartsDataView.RowFilter = Nothing Return True End If messageString = messageString + "Addpartsdataview.count equals " + addPartsDataView.Count.ToString + ", " End If 'for debugging only test = addPartsDataView(0) testpartNum = test.Item("PartNum") MsgBox(messageString) 'if we are here then part already exists Return False End Function
Thanks in advance
Comment