|
-
Jun 15th, 2006, 07:17 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Replace Quotation
HI! I have succesfully used the code below to replaced quotation mark ( ' ) however, if i use the same code in my search textbox it gives me error. How do i let my search box accept quotation mark?
VB Code:
Function doQuery(ByVal sCriteria As String, ByVal sfieldName As String) As String
doQuery = "SELECT Code, ProductDescription, SellingPrice,PurchasePrice,Quantity, " & _
"Unit,EntryDate, ReOrder FROM tblStocks " & _
"WHERE " & sfieldName & " LIKE '" & sCriteria & "%'"
End Function
Private Sub txtSearch_Change()
Dim rsStocks1 As New ADODB.Recordset
sSQL = doQuery(txtSearch.Text, "ProductDescription")
rsStocks1.Open sSQL, oConn, adOpenForwardOnly, adLockOptimistic
If rsStocks1.EOF = False Then
Call FillListView(lstStocks, rsStocks1)
End If
End Sub
-
Jun 15th, 2006, 07:19 AM
#2
Hyperactive Member
Re: Replace Quotation
VB Code:
LIKE '" & replace(sCriteria, "'", "''")
-
Jun 15th, 2006, 07:25 AM
#3
Thread Starter
PowerPoster
Re: Replace Quotation
 Originally Posted by whythetorment
VB Code:
LIKE '" & replace(sCriteria, "'", "''")
Thanks for the reply. But as i've said i have successfully used replace quotation. I need to implement the same when the user type for example (Hershey's) the app should accept it.
here's my replace quotation code.
VB Code:
Public Sub ReplaceQuotation(ByRef txt1 As TextBox)
txt1.Text = Replace(txt1.Text, "'", "''", , , vbTextCompare)
End Sub
-
Jun 15th, 2006, 07:28 AM
#4
Re: Replace Quotation
The best way to handle these special characters is to use Parametrized Queries. These queries are faster and safer compared to the T-SQL. Take a look at this thread.
http://www.vbforums.com/showthread.php?t=402848
And have you written any code in your textbox keypress event that will disable apostrophes??
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 15th, 2006, 07:34 AM
#5
Re: Replace Quotation
Just hit the replace in the doQuery, but as Shuji mentioned.. I would change it to a Param query...
VB Code:
Function doQuery(ByVal sCriteria As String, ByVal sfieldName As String) As String
If InStr(sCriteria, "'") <> 0 Then
sCriteria = Replace(sCriteria, "'", "''")
End If
doQuery = "SELECT Code, ProductDescription, SellingPrice,PurchasePrice,Quantity, " & _
"Unit,EntryDate, ReOrder FROM tblStocks " & _
"WHERE " & sfieldName & " LIKE '" & sCriteria & "%'"
End Function
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jun 15th, 2006, 07:41 AM
#6
Thread Starter
PowerPoster
Re: Replace Quotation
thanks to both of you guys. I'll have to take a look the link you gave shuja Ali
-
Jun 15th, 2006, 07:50 AM
#7
Thread Starter
PowerPoster
Re: Replace Quotation
 Originally Posted by Shuja Ali
The best way to handle these special characters is to use Parametrized Queries. These queries are faster and safer compared to the T-SQL. Take a look at this thread.
http://www.vbforums.com/showthread.php?t=402848
And have you written any code in your textbox keypress event that will disable apostrophes??
I followed the link you gave. Im sorry but i really can't get how do i implement Parameterized Queries and where in the link is it?
-
Jun 15th, 2006, 07:55 AM
#8
Re: Replace Quotation
 Originally Posted by Simply Me
I followed the link you gave. Im sorry but i really can't get how do i implement Parameterized Queries and where in the link is it?
It is in this post.
What exactly are you not able to understand?
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 15th, 2006, 08:02 AM
#9
Thread Starter
PowerPoster
Re: Replace Quotation
The title says How do i Validate Textbox Preventing Single ' & Double " but i don't want to prevent it.
If im missing your point however, please kindly show me how do i implement it with the code i have currently.
-
Jun 15th, 2006, 08:06 AM
#10
Thread Starter
PowerPoster
Re: Replace Quotation
im sorry, I have re-read the title. I thought it was about preventing it, my mistake.
Anyway could you show me how to implement your code please?
Last edited by Simply Me; Jun 15th, 2006 at 08:38 AM.
-
Jun 15th, 2006, 08:36 AM
#11
Re: Replace Quotation
See instead of directly assigning the value in the SQL Query you create a parameter and then assign the value to that parameter.
It would be better if you give it a try yourself and then post whatever problemyou face.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Jun 15th, 2006, 07:04 PM
#12
Thread Starter
PowerPoster
Re: [RESOLVED] Replace Quotation
Thanks Shuja Ali. I just followed the code of static.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|