?
Solved

Search string with apostrophe or comma

Posted on 2012-08-22
3
Medium Priority
?
601 Views
Last Modified: 2012-08-22
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
Comment
Question by:eharford
  • 3
3 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 38320694
replace apostrophe with ''

str.Replace("'","''")
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38320704
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
 
LVL 35

Accepted Solution

by:
YZlat earned 1200 total points
ID: 38320713
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question