Results 1 to 4 of 4

Thread: Painful Error....

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    13

    Thumbs down Painful Error....

    Hi...
    i m inserting a string type into data base. i got the strange type of a error. i've control Text1 on the form, i enter some value into the text box like
    "Hi it's me ROAMER"
    My insert query states
    Insert InTo demo(Notes) VALUES ('" & Text1.Text & "')
    it gives me the Error. when i ommit the ' char from it's me ROAMER then the insert query inserts the data into data base. Problem is with ' char.
    can any one plz help me.

  2. #2
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306

    Re: Painful Error....

    use the CSQL function

    here is the definition:
    VB Code:
    1. Public Function CSQL(SQLCMD As String)
    2.      If IsEmpty(SQLCMD) Or IsNull(SQLCMD) Then CSQL = "''" Else CSQL = "'" & Replace(SQLCMD, "'", "''") & "'"
    3. End Function

    now with your insert statment go:
    INSERT INTO Demo(notes) VALUES(" & CSQL(Text1.Text) & ")"

    note: the csql will add the beginning ' and the end ' while replacing all other ' to '' making them a single quote inserted to the database.


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  3. #3
    New Member
    Join Date
    Mar 2006
    Location
    Vidin
    Posts
    15

    Re: Painful Error....

    VB Code:
    1. Public Function AddSlashes(strText As String) As String
    2.  strText = Replace$(strText, Chr(34), "\" & Chr(34))
    3.  strText = Replace$(strText, Chr(39), "\" & Chr(39))
    4.  
    5.  AddSlashes = strText
    6. End Function
    7.  
    8. Public Function StripSlashes(Text As String) As String
    9.  Text = Replace$(Text, "\" & Chr(34), Chr(34))
    10.  Text = Replace$(Text, "\" & Chr(39), Chr(39))
    11.  
    12.  StripSlashes = Text
    13. End Function

    Use the first function whenever you add data to your DB. It puts in front of all quotes \. And when you get data from DB use StripSlashes, it removes \ in fron of the quotes.



    Freedom Has Its Own Style

  4. #4
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Painful Error....

    However, if you something like Crystal Report Writer to list data, will will have the slashes instead of apostrophies.

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