Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by PlausiblyDamp
  • Moderators
Posted

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 & "')"

Visit...Bassic Software

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...