Results 1 to 6 of 6

Thread: Insert Statement

  1. #1
    byeadon
    Guest

    Insert Statement

    I have been trying to come up with some sort of SQL statement or anthing for that matters that will allow me to type ANYTHING into a field in my Visual Basic Program and save it into an access 2000 database. I able to account for a singel quote but commas and others keep giving me the missing operator in query expression, I anyone knows how to account for anything entered into a field i would be greatly appericate it, Iam using VB6, Access 2000 and ADODB Connections.

    Brad

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    well i use this

    I use this in asp pages. i don't see why it can't be used in a vb app.
    VB Code:
    1. Public Function HTMLDecodeChar( _
    2.     ByVal lszEncodedChr As String _
    3. )   '*****************************************************************************************
    4.         Dim sRet As String
    5.        
    6.         sRet = Chr(Mid$(lszEncodedChr, 3, Len(lszEncodedChr)))
    7.         HTMLDecodeChar = sRet
    8.     '*****************************************************************************************
    9. End Function
    10.  
    11. Public Function HTMLDecodeString( _
    12.     ByVal lszEncoded As String, _
    13.     ByRef lszEncodedChars, _
    14.     ByVal cEncodedChars As Long _
    15. )   '*****************************************************************************************
    16.     Dim sRet As String, sReplace As String, i As Integer
    17.    
    18.     For i = 0 To cEncodedChars
    19.         sReplace = HTMLDecodeChar(lszEncodedChars(i))
    20.         If i = 0 Then
    21.             sRet = Replace(lszEncoded, sReplace, lszEncodedChars(i))
    22.         Else
    23.             sRet = Replace(sRet, sReplace, lszEncodedChars(i))
    24.         End If
    25.     Next i  ' i = 0 To lcEncodedChars
    26.    
    27.     HTMLDecodeString = sRet
    28.     '*****************************************************************************************
    29. End Function
    30.  
    31. Public Function HTMLEncodeChar( _
    32.     ByVal lszEncodeChr As String _
    33. )   '*****************************************************************************************
    34.         Dim sRet As String
    35.         sRet = "&#" & Asc(lszEncodeChr)
    36.         If Len(sRet) = 4 Then sRet = Mid$(sRet, 1, 2) & "0" & Mid$(sRet, 3, 4)
    37.         HTMLEncodeChar = sRet
    38.     '*****************************************************************************************
    39. End Function
    40.  
    41. Public Function HTMLEncodeString( _
    42.     ByVal lszEncode As String, _
    43.     ByRef lszEncodeChars, _
    44.     ByVal cEncodeChars As Long _
    45. )   '*****************************************************************************************
    46.     Dim sRet As String, sReplace As String, i As Integer
    47.    
    48.     For i = 0 To cEncodeChars
    49.         sReplace = HTMLEncodeChar(lszEncodeChars(i))
    50.         If i = 0 Then
    51.             sRet = Replace(lszEncode, lszEncodeChars(i), HTMLEncodeChar(lszEncodeChars(i)))
    52.         Else
    53.             sRet = Replace(sRet, lszEncodeChars(i), sReplace)
    54.         End If
    55.     Next i  ' i = 0 To lszEncodeChars
    56.    
    57.     HTMLEncodeString = sRet
    58.     '*****************************************************************************************
    59. End Function

    all you need to do to make use of it is loop through the contents of the field before insert and incode those nasty charecters and do the same upon redisply except decode

    there is a better way though its called a stored proc i will make you an example and post it
    Magiaus

    If I helped give me some points.

  3. #3
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    duh

    i forgot i already made the looping code you can use HTMLEncodeString like so

    VB Code:
    1. sToInsert = HTMLEncodeString(theString,Array("'","&"),Len(Array("'","&")))
    Magiaus

    If I helped give me some points.

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    stored proc example

    the real trick is knowing how to change the query type and setup the SQL in Access but it is in the help file.
    Attached Files Attached Files
    Magiaus

    If I helped give me some points.

  5. #5
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    that trick is good for almost all types of SQL and it can save you from all those repeated SQL statements in your code and from so other nasty things that can come up

    and this is the vb.net forum not the db forum
    Magiaus

    If I helped give me some points.

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    with autonumber

    here

    look in db no vb changes
    Magiaus

    If I helped give me some points.

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