Results 1 to 12 of 12

Thread: [RESOLVED] Replace Quotation

  1. #1

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Resolved [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:
    1. Function doQuery(ByVal sCriteria As String, ByVal sfieldName As String) As String
    2.   doQuery = "SELECT Code, ProductDescription, SellingPrice,PurchasePrice,Quantity, " & _
    3.             "Unit,EntryDate, ReOrder FROM tblStocks " & _
    4.               "WHERE " & sfieldName & " LIKE '" & sCriteria & "%'"
    5. End Function
    6.  
    7. Private Sub txtSearch_Change()
    8.   Dim rsStocks1 As New ADODB.Recordset
    9.   sSQL = doQuery(txtSearch.Text, "ProductDescription")
    10.   rsStocks1.Open sSQL, oConn, adOpenForwardOnly, adLockOptimistic
    11.  
    12.   If rsStocks1.EOF = False Then
    13.     Call FillListView(lstStocks, rsStocks1)
    14.   End If
    15. End Sub
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  2. #2
    Hyperactive Member
    Join Date
    May 2005
    Posts
    307

    Re: Replace Quotation

    VB Code:
    1. LIKE '" & replace(sCriteria, "'", "''")

  3. #3

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Replace Quotation

    Quote Originally Posted by whythetorment
    VB Code:
    1. 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:
    1. Public Sub ReplaceQuotation(ByRef txt1 As TextBox)
    2.   txt1.Text = Replace(txt1.Text, "'", "''", , , vbTextCompare)
    3. End Sub
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Replace Quotation

    Just hit the replace in the doQuery, but as Shuji mentioned.. I would change it to a Param query...
    VB Code:
    1. Function doQuery(ByVal sCriteria As String, ByVal sfieldName As String) As String
    2.     If InStr(sCriteria, "'") <> 0 Then
    3.         sCriteria = Replace(sCriteria, "'", "''")
    4.     End If
    5.     doQuery = "SELECT Code, ProductDescription, SellingPrice,PurchasePrice,Quantity, " & _
    6.             "Unit,EntryDate, ReOrder FROM tblStocks " & _
    7.               "WHERE " & sfieldName & " LIKE '" & sCriteria & "%'"
    8. End Function
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Replace Quotation

    thanks to both of you guys. I'll have to take a look the link you gave shuja Ali
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  7. #7

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: Replace Quotation

    Quote 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?
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  8. #8
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Replace Quotation

    Quote 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

  9. #9

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    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.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  10. #10

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    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.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

  11. #11
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    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

  12. #12

    Thread Starter
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: [RESOLVED] Replace Quotation

    Thanks Shuja Ali. I just followed the code of static.
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width