octipuss Posted June 11, 2003 Posted June 11, 2003 (edited) I'm just not seeing where the cast exception is coming from. Any help appreciated. An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll Additional information: Cast from string "SELECT Description Like '%CRC%'" to type 'Long' is not valid. The code is setup to take a user-entered criteria from a text box once a "select all" value from a listbox has been selected. It then cycles through each column looking for the user-defined string. The code works just fine when a specific column heading is selected from the listbox so I don't understand why the use of multiple column headings in a SQL/OR or statement doesn't also work. If cbChooseCol.SelectedItem = ("[select All]" ) Then Dim field1, criterial As String field1 = "PartMaster." criterial = txtCriterial.Text criterial.StartsWith("" ) .Clear() .DefaultView.RowFilter = _ "SELECT Description Like '%" & txtCriterial.Text & "%'" Or _ "[Vendor] like '%" & txtCriterial.Text & "%'" Or _ "Notes like '%" & txtCriterial.Text & "%'" Or _ ' code continues until .......... "from PartMaster WHERE ," & _ "(" & field1 & " = '" & criterial & " ')" Edited November 27, 2005 by PlausiblyDamp Quote
Moderators Robby Posted June 11, 2003 Moderators Posted June 11, 2003 You need to place your OR inside the quotes... .DefaultView.RowFilter = _ "SELECT Description Like '%" & txtCriterial.Text & "%' Or " & _ "[Vendor] like '%" & txtCriterial.Text & "%' Or " & _ "Notes like '%" & txtCriterial.Text & "%'" & _ "from PartMaster WHERE ," & _ "(" & field1 & " = '" & criterial & "')" Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.