Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2005
    Posts
    1

    Unanswered: i have problem regarding SELECT query statements in VB6

    i have problem regarding SELECT query statements in VB6. I want to open the record in a database. that record has an appostrophy or single quote symbol becuase it contains words with "appostrophy s". when i want to retrieve it, and place it in the textbox, there is a runtime error explains syntax error (missing operator)in the query expression = '. how to solve that runtime error. this is example of code:

    Private Sub listenglish_ItemClick(ByVal Item As MSComctlLib.ListItem)
    Dim rstpos As Recordset
    Set rstpos = New Recordset
    If rstpos.State = adStateOpen Then
    rstpos.Close
    End If
    rstpos.CursorLocation = adUseClient
    rstpos.CursorType = adOpenDynamic
    rstpos.LockType = adLockOptimistic
    With rstpos
    .ActiveConnection = mcnnproj
    .Source = "SELECT english from translation where english ='" & listenglish.SelectedItem & "'"
    .Open
    End With

    RichTextBox1.Text = rstpos!english

    rstpos.Close
    Set rstpos = Nothing

    End Sub

    my problem here is in: "SELECT english from translation where english ='" & listenglish.SelectedItem & "'"
    .Open

    Hope anyone will help me in this problem. i need to solve this problem immediately. thanks

    blu_wash

  2. #2
    Join Date
    Oct 2004
    Location
    In cousin's house
    Posts
    303

    Smile

    You can used a parameter query or a Stored procedure.

  3. #3
    Join Date
    Jan 2005
    Posts
    18
    Can u just give me the error message that appears in the screen. Hope i could help u

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'd use ADO parameter substitution (using ?), or I'd use a function to handle quoting for my code.

    The problem is that in SQL syntax, a quote ends a string. To get a literal apostrophe, you need to double it, like:
    Code:
    SELECT 'I can''t get apostrophes past SQL any other way!'
    Using the ADO parameter routines does this quoting "automagically" for you.

    -PatP

Posting Permissions

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