Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2007, 09:32 AM
Authorized User
 
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default BindingSource.Filter

I am having issues with filtering with the Like operand. If the data type of the column in my datagrid is a string it works perfectly but if it is a dateandtime or integer it will not work...gives generic EvaluateException referring to the datacolumn not being able to be evaluated. I understand that the Like statement is used on strings, booleans, and binary values. But there should be away for me to convert the data. Does it need to be converted in the stored procedure when the datagridview is loaded or can I do it in the vb code?

Here is my code:
Select Case cbSearch.SelectedIndex
            Case 0
                Me.PalletBindingSource.Filter = "PalletID like'" & txtSearch.Text & "%" & "'"
                If dgPallet.RowCount > 1 Then
                    Exit Sub
                Else
                    subBind()
                End If
            Case 1
                Me.PalletBindingSource.Filter = "ItemNum Like'" & txtSearch.Text & "%" & "'"
                If dgPallet.RowCount > 1 Then
                    Exit Sub
                Else
                    subBind()
                End If
            Case 2
                Me.PalletBindingSource.Filter = "EntryDt Like'" & txtSearch.Text & "%" & "'"
                If dgPallet.RowCount > 1 Then
                    Exit Sub
                Else
                    subBind()
                End If
        End Select

Case 1 works but Case 0 and 2 give me the error.

I have tried converting both txtSearch.Text & PalletID to strings but still errors out. Any ideas?

Thank you,
John Williams
__________________
Thank you,
John Williams
 
Old May 23rd, 2007, 10:07 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

You can filter a BindingSource integer or date column by using >= and/or <=

Example:

Me.PalletBindingSource.Filter = "PalletID >= " & txtSearch.Text


If you need to further filter your pallets you could add another textbox and try this:

Me.PalletBindingSource.Filter = "PalletID >= " & txtSearch.Text & " AND PalletID <= " & txtSearch2.text

The same would apply for date ranges.

Hopefully this helps.



Best Regards,
Earl Francis
 
Old May 23rd, 2007, 10:16 AM
Authorized User
 
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you! I will actually use that in the next part of my form but I found a solution to my question. I went in and change my stored procdure from:
select PalletID, a.ItemNum, Qty, EmpID, EntryDt
from dbo.pallet a inner join dbo.item b on a.itemnum = b.itemnum
where b.statuscode not in ('3','4')

To:

select Convert(char(8),PalletID) as PalletID, a.ItemNum, Qty, EmpID, Convert(Char(25),EntryDt, 120) as EntryDt
from dbo.pallet a inner join dbo.item b on a.itemnum = b.itemnum
where b.statuscode not in ('3','4')

Since it is being past in a char value I was able to use the Like statement against it.

Thanks again for the help!


Thank you,
John Williams





Similar Threads
Thread Thread Starter Forum Replies Last Post
bindingSource position after table.AddRow() miroslavign .NET Framework 2.0 1 September 12th, 2006 02:15 PM
bindingsource validating gpizzuto Visual Basic 2005 Basics 0 April 26th, 2006 05:27 PM
Expression Filter dba123 Reporting Services 5 March 3rd, 2006 11:35 AM
Filter Help mcloum Classic ASP Databases 2 November 10th, 2005 05:40 PM
Filter Help mcloum BOOK: Beginning ASP 3.0 1 August 26th, 2005 03:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.