• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 605
  • Last Modified:

Search string with apostrophe or comma

Have a DropdownList to pick from which then populates Gridview. This works fine until the search value has ' in it. Eg: Search value = "D'Orgeix, Christian". It works fine with "Fischer, Lothar"

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim ds As Data.DataSet
ds = CType(Session("myds"), Data.Dat aSet)
ds.Tables("Inventory").DefaultView.RowFilter = "ArtistMaker= '" & DropDownList1.SelectedItem.Text & "'"
dgPInv.DataSource = ds.Table("Inventory")
dgPInv.DataBind()
Session("myds") = ds
End Sub
0
eharford
Asked:
eharford
  • 3
1 Solution
 
YZlatCommented:
replace apostrophe with ''

str.Replace("'","''")
0
 
YZlatCommented:
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim ds As Data.DataSet
ds = CType(Session("myds"), Data.Dat aSet)
ds.Tables("Inventory").DefaultView.RowFilter = "ArtistMaker= '" & DropDownList1.SelectedItem.Text.Replace("'","''") & "'"
dgPInv.DataSource = ds.Table("Inventory")
dgPInv.DataBind()
Session("myds") = ds
End Sub 

Open in new window

0
 
YZlatCommented:
or

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

Dim ds As Data.DataSet
Dim str as String
ds = CType(Session("myds"), Data.Dat aSet)
str=DropDownList1.SelectedItem.Text
ds.Tables("Inventory").DefaultView.RowFilter = "ArtistMaker= '" & str.Replace("'","''") & "'"
dgPInv.DataSource = ds.Table("Inventory")
dgPInv.DataBind()
Session("myds") = ds
End Sub 

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now